我正在努力使用send_file
rails 3.0.9在ubuntu lucid上运行ruby 1.9,apache上的乘客3.0.8 xsendfile模块已安装并加载到apache
root~# a2enmod xsendfile
Module xsendfile already enabled
Run Code Online (Sandbox Code Playgroud)
它在启用mods时正确符号链接
lrwxrwxrwx 1 root root 32 Aug 8 11:20 xsendfile.load -> ../mods-available/xsendfile.load
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud) 我们在使用默认的rails 3应用程序在ipad上播放mp4时遇到问题.在Chrome和桌面上的其他浏览器中查看路径时,可以正确提供mp4.
这是我们的代码:
file_path = File.join(Rails.root, 'test.mp4')
send_file(file_path, :disposition => "inline", :type => "video/mp4")
Run Code Online (Sandbox Code Playgroud)
我们点击0.0.0.0:3000/video/test.mp4观看视频,并在ipad上显示无法播放图标.我们已经尝试修改各种标题"Content-Length","Content-Range"等,但它们似乎不会影响最终结果.
我们也尝试过在某种程度上使用send_data
即
File.open(file_path, "r") do |f|
send_data f.read, :type => "video/mp4"
end
Run Code Online (Sandbox Code Playgroud)
在Ipad上查看时,同一视频在公共文件夹中正常运行.
通过rails到Ipad提供mp4文件的正确方法是什么?
我有以下问题.声音在公共文件夹中隐藏,因为只有某些用户应该有权访问声音文件.所以我做了一个特定的方法,它就像一个声音网址,但首先计算,是否允许当前用户访问此文件.
该文件由send_data方法发送.问题是,如果它工作得很好我工作得很慢...我用来播放声音的jplayer插件的开发者告诉我,我应该能够接受字节范围请求以使其正常工作...
如何通过发送带有send_data或send_file的文件在rails控制器中执行此操作?
谢谢你,马库斯