Joe Van Dyk
2006-Feb-28 11:07 UTC
[Rails] ArgumentError (string contains null byte) -- file upload problem
Hi, Controller code: if params[:main_image] image = Image.new image.blob = params[:main_image].read @product.main_image.destroy if @product.main_image @product.main_image = image end When I try to display the image using send_data, I get the following error: ArgumentError (string contains null byte): .//vendor/rails/actionpack/lib/action_controller/streaming.rb:55:in `file?'' .//vendor/rails/actionpack/lib/action_controller/streaming.rb:55:in `send_file'' .//app/controllers/images_controller.rb:5:in `show'' Here''s the image controller: class ImagesController < ApplicationController def show image = Image.find params[:id] send_file image.blob, :type => ''image/jpeg'', :disposition => ''inline'' end end Any ideas? Joe
Joe Van Dyk
2006-Feb-28 11:50 UTC
[Rails] Re: ArgumentError (string contains null byte) -- file upload problem
Gah, I wanted send_data, not send_file. On 2/28/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> Hi, > > Controller code: > if params[:main_image] > image = Image.new > image.blob = params[:main_image].read > @product.main_image.destroy if @product.main_image > @product.main_image = image > end > > When I try to display the image using send_data, I get the following error: > ArgumentError (string contains null byte): > .//vendor/rails/actionpack/lib/action_controller/streaming.rb:55:in `file?'' > .//vendor/rails/actionpack/lib/action_controller/streaming.rb:55:in > `send_file'' > .//app/controllers/images_controller.rb:5:in `show'' > > > Here''s the image controller: > class ImagesController < ApplicationController > def show > image = Image.find params[:id] > send_file image.blob, :type => ''image/jpeg'', :disposition => ''inline'' > end > end > > Any ideas? > Joe >