【发布时间】:2011-06-19 15:07:07
【问题描述】:
我想将http://foobar.com/song.mp3 下载为song.mp3,而不是让Chrome 在浏览器的本机<audio> 播放器中打开它。
我怎样才能完成这个?
【问题讨论】:
我想将http://foobar.com/song.mp3 下载为song.mp3,而不是让Chrome 在浏览器的本机<audio> 播放器中打开它。
我怎样才能完成这个?
【问题讨论】:
您只需要确保发送这些标头:
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
【讨论】: