Amazon AWS S3 强制下载 Mp3 文件而不是流式传输
我使用 Amazon S3 放置 mp3 文件,然后允许我们的网站访问者从 Amazon AWS 下载 mp3。我使用 S3Fox 来管理文件,一切似乎都工作正常,直到最近我们收到访客的许多投诉,称 mp3 是通过浏览器传输的,而不是显示浏览器保存对话框。 我尝试播放一些 mp3,注意到对于某些 mp3,会出现保存对话框,而对于其他一些 mp3,它们是通过浏览器进行流式传输。我能做什么来强制下载 mp3 文件而不是通过网络浏览器流式传输......
任何帮助将不胜感激。 谢谢
I'm using Amazon S3 to put the mp3 file then allow our site visitor to download the mp3 from Amazon AWS. I use S3Fox to manage the file, everything seems working fine until recently we got many complaints from visitor that the mp3 was streamed via the browser instead of displaying browser save dialog.
I try for some mp3 and notice that for some mp3, the save dialog box is appear, and for some others they're streamed via browser. What can I do to force that the mp3 file will be downloaded instead of streamed via web browser....
Any help would be much appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为此,您需要设置 Content-Disposition 标头:
我认为这对于 S3Fox 是不可能的。您可以使用 Bucket Explorer(非免费)或编写脚本来上传文件。
In order to do so you need to set the Content-Disposition header:
I don't think this is possible with S3Fox. You could use Bucket Explorer (not free) or write a script to upload the files.
好吧,自从你问这个问题以来已经很长时间了,但我遇到了同样的问题,我想与社区分享我的解决方案,以防万一其他人需要解决这个问题。当然,您可以从 Amazon S3 控制台更改 Content-Type 和 Content-Disposition,但有趣的是以编程方式执行此操作。
以下代码对我来说效果很好:
希望它可以帮助其他遇到同样问题的人。
Ok, it's been a long time since you ask this, but I had the same problem and I'd like to share my solution with the community, just in case someone else need to solve this thing. Of course, you can change Content-Type and Content-Disposition from the Amazon S3 Console, but the interesting thing is to do it programmatically.
The following code works fine for me:
Hope it can helps other struggling with the same trouble.
这最终成为我从 AWS S3 强制下载文件的解决方案。
在 safari 中,文件以 .html 文件的形式下载,直到我停止返回读取文件并单独运行该函数。
This ended up being my solution for force downloading files from AWS S3.
In safari the files were downloading as .html files until I stopped returning the readfile and just ran the function alone.
在 s3 管理控制台窗口中,右键单击并选择属性。
单击元数据。
单击添加更多元数据
密钥:内容处置
值:附件保存
。就这样。
In s3 management console window, right click and chose properties.
Click on metadata.
Click on add more metadata
Key: content-disposition
Value: attachment
Save. That's all.