Rails 3: Image streaming error: “The image … cannot be displayed because it contains errors” -


the log says:

started "/assets/2/thumb" 110.174.88.80 @ fri jul 01 20:11:35 -0700 2011   processing assetscontroller#show html   parameters: {"id"=>"2", "style"=>"thumb"} [/home/misha_moroshko/myfamily.moroshko.com/public/images/thumb.jpg] found! sent file /home/misha_moroshko/myfamily.moroshko.com/public/images/thumb.jpg (0.2ms) completed 200 ok in 2ms 

if go directly image, fetched properly.

note simplified example of real problem. in real case image not in public folder, error same.

what cause such error ?


rails -v => rails 3.0.1 ruby -v => ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] 

relevant code:

# config/routes.rb match "assets/:id/:style" => "assets#show"  class assetscontroller < applicationcontroller   def show     path = rails.root.join("public", "images", "thumb.jpg").to_s     if file.exist?(path)       logger.fatal "[#{path}] found!"       send_file(path, { :type => "image/jpeg", :disposition => "inline" })     else       logger.fatal "[#{path}] not found!"     end   end end 

replacing

config.action_dispatch.x_sendfile_header = "x-sendfile" 

with

config.action_dispatch.x_sendfile_header = "x-accel-redirect" 

in config/environments/production.rb solved problem!


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -