Rails 3: Image Streaming Error: "Image ... cannot be displayed because it contains errors"

The magazine says:

Started GET "/assets/2/thumb" for 110.174.88.80 at Fri Jul 01 20:11:35 -0700 2011 Processing by AssetsController#show as 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 you go directly to the image, it will be loaded correctly.

Please note that this is a simplified example of my real problem. In the real case, the image is not in the public folder, but the error is the same.

What can cause such an 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 
+4
source share
2 answers

Replacement

 config.action_dispatch.x_sendfile_header = "X-Sendfile" 

with

 config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" 

in config/environments/production.rb solved the problem!

+5
source

The URL http://www.myfamily.moroshko.com/assets/2/thumb sends the correct headers, but does not send the body in response. Did you remove the code that @amb suggested adding? It seems to go into your else block and just log the error on your console.

0
source

All Articles