Forum: Ruby on Rails ArgumentError (string contains null byte) -- file upload pro

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joe Van D. (Guest)
on 2006-02-28 13:09
(Received via mailing list)
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 D. (Guest)
on 2006-02-28 13:52
(Received via mailing list)
Gah, I wanted send_data, not send_file.
This topic is locked and can not be replied to.