日志说:
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
如果您直接转到图像,则可以正确获取。
请注意,这是我的实际问题的简化示例。在实际情况下,图像不在
public
中文件夹,但错误是一样的。什么会导致这样的错误?
rails -v
=> Rails 3.0.1
ruby -v
=> ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
相关代码:
# 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
最佳答案
更换
config.action_dispatch.x_sendfile_header = "X-Sendfile"
和
config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"
在
config/environments/production.rb
解决了问题!
关于ruby-on-rails - rails 3 : Image streaming error: “The image … cannot be displayed because it contains errors” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6554923/