Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails:音频/mp3内容头下载_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails RubyonRails:音频/mp3内容头下载

Ruby on rails RubyonRails:音频/mp3内容头下载,ruby-on-rails,ruby,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);

如何在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将如何/在何处发挥作用以及其他头文件


谢谢

找到了答案。控制器中应使用send_文件

  def download
       send_file "/path/to/file.mp3", :type=>"audio/mp3", :filename => "filenamehere.mp3"
  end
rails进程限制还有一些其他考虑因素:

请看这里:

另外,发送文件