ruby on rails:音频/ mp3内容标题下载

时间:2010-05-13 20:51:38

标签: ruby-on-rails ruby

如何在ruby / rails中设置下载标题?

在php中,我为这样的mp3下载设置了标题:

    header("Content-Transfer-Encoding: binary");
    header("Content-type: audio/mp3");
    header("Content-Disposition: attachment; filename=\"$songname.mp3\"");
    header("Content-Length: " . $size);

    @readfile("http://example.com/12345.mp3");

似乎应该有一个简单的解决方案。

我确实找到了这个:

response.headers['Content-type'] = 'Content-type: audio/mp3'

但我不确定readfile将如何/在哪里发挥作用以及其他标题。

谢谢!

1 个答案:

答案 0 :(得分:6)

找到答案。 send_file应该在控制器中使用。

  def download
       send_file "/path/to/file.mp3", :type=>"audio/mp3", :filename => "filenamehere.mp3"
  end

对于rails进程限制还有一些其他注意事项:

见这里: http://www.therailsway.com/2009/2/22/file-downloads-done-right

另外,send_file http://apidock.com/rails/ActionController/Streaming/send_file

相关问题