Rails 文件下载 为什么 send_data 可以 send_file 不行?

ripple · 2012年03月07日 · 最后由 kgen 回复于 2012年03月08日 · 9779 次阅读

下面这个 send_data 可以 File.open(@resultFile, 'rb') do |f| send_data f.read, :disposition => "inline",:stream => false,:filename => 'result.mat' end

这个 send_file 就不行 send_file(@resultFile, :disposition => 'inline', :filename => "result.mat")

send_file 下载以后文件只有 404K,不是真实大小,原来真实文件大小 307k。

问什么不让 Nginx 或 Apache 直接指向那个文件呢?

x-sendfile? Rack::Sendfile - Enables X-Sendfile support for bodies that can be served from file.

如果没有权限控制的需求,静态资源还是让 Nginx/Apache 直接发送,app 里面只要 URL 正确即可。

#1 楼 @huacnlee 是在 webrick 测试得

#2 楼 @hlxwell 我也看到这个选项,不过都说是在 nginx 这类生产环境服务器得时候使用得,webrick 不用设置这个

#3 楼 @kgen 开始是想整个先在 webrick 测试过了,再到生产环境去测试

#6 楼 @ripple 那可以本机装个 Nginx 吧,因为原理不同,你在 Webrick 上发送文件正常,依然可能在 Nginx/Apache 上不正常。

#7 楼 @kgen 以前都是用 nginx+passanger,不过 jruby 一般生产服务器用什么呢?tomcat?

#8 楼 @ripple 嗯,这是目前公认最佳部署方式,JRuby 的部署,还是看 Java 社区的主流情况了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号