gpt4 book ai didi

ruby - 强制浏览器下载文件而不是打开文件

转载 作者:数据小太阳 更新时间:2023-10-29 07:11:21 25 4
gpt4 key购买 nike

我要下载http://foobar.com/song.mp3作为song.mp3 ,而不是让 Chrome 在其 native 中打开它 <audio>浏览器中的播放器。

我怎样才能做到这一点?

最佳答案

您只需要确保发送这些 header :

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

关于ruby - 强制浏览器下载文件而不是打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4868945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com