send_file just sends an empty file

自闭症网瘾萝莉.ら 提交于 2019-12-01 02:45:43

probably you have to comment out

config.action_dispatch.x_sendfile_header = "X-Sendfile"

in production.rb

see http://vijaydev.wordpress.com/2010/12/15/rails-3-and-apache-x-sendfile/ for explanations

Problem saved, but I don't know why

File.open(file_path, 'r') do |f|
  send_data f.read, :type => "text/xml", :filename => "10.xml"
end

send_data is working... but send_file not!

As Eugene says in his answer, in a production enviroment Rails will let Apache or nginx send the actual file for you with x-sendfile, if you don't use either of these as the infrastructure for rails you have to comment out the line suggested in the

config/environments/production.rb file.

# config.action_dispatch.x_sendfile_header = "X-Sendfile"

You must enable sendfile usage in ./config/environments/production.rb:

config.action_dispatch.x_sendfile_header = "X-Sendfile"

If this line is not present (or commented out), then Rails will correctly send the file, but not through Apache.

If you are getting 0-byte files, then make sure that you have installed mod_xsendfile, which is available from https://tn123.org/mod_xsendfile

Download the single source file (mod_xsendfile.c) and compile it (apxs -cia mod_xsendfile.c). You probably want to run apxs as root so that it will set up everything correctly.

Then you're going to want to set the XSendFile and XSendFilePath options in your Apache configuration files. See the help at the above URL for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!