Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – Rails 3,apache和passenger,send_file发送零字节文件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在努力与send_file与rails 3.0.9运行 ruby 1.9,乘客3.0.8在apache上ubuntu清
xsendfile模块已安装并加载到apache中
root~# a2enmod xsendfile
Module xsendfile already enabled

它已启用mods正确符号

lrwxrwxrwx 1 root root   32 Aug  8 11:20 xsendfile.load -> ../mods-available/xsendfile.load

config.action_dispatch.x_sendfile_header =“X-Sendfile”在我的production.rb中设置

使用send_file结果将零字节文件发送到浏览器

filepath = Rails.root.join('export',"#{filename}.csv")
if File.exists?(filepath)
  send_file filepath,:type => 'text/csv'
end

解决方法

我相信以前的答案不是正确的方法,因为据我所知,当应用这个解决方案时,Apache并没有处理下载,而是使用Rails进程.这就是为什么nginx指令看起来不行.您可以通过注释掉配置指令来获得相同的结果.

另一个缺点(除了绑定一个rails进程太久),当数据流由rails进程处理时,响应似乎没有发送内容长度头.所以用户不知道他们下载的文件有多大,也不知道需要多长时间(可用性问题).

我可以通过确保mod_sendfile正确地包含在我的apache配置中并加载到我的apache配置中,这样就可以得到它(这将取决于你的apache安装等等):

LoadModule xsendfile_module   /usr/lib64/httpd/modules/mod_xsendfile.so
...

# enable mod_x_sendfile for offloading zip file downloads from rails 
XSendFile on 
XSendFilePath /

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – Rails 3,apache和passenger,send_file发送零字节文件全部内容,希望文章能够帮你解决ruby-on-rails – Rails 3,apache和passenger,send_file发送零字节文件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。