我想将http://foobar.com/song.mp3下载为song.mp3
,而不是让Chrome在浏览器中的原生<audio>
播放器中打开它。
我怎样才能这样做?
答案 0 :(得分:12)
您只需确保发送以下标题:
Content-Disposition: attachment; filename=song.mp3;
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
send_file
方法适合您:
get '/:file' do |file|
file = File.join('/some/path', file)
send_file(file, :disposition => 'attachment', :filename => File.basename(file))
end