【问题标题】:What S3 cors config should I use for Firefox html5 download attribute?我应该为 Firefox html5 下载属性使用什么 S3 cors 配置?
【发布时间】:2017-10-11 22:25:36
【问题描述】:

我正在使用 HTML5 下载属性来允许用户从 S3 下载视频文件:

<a href="https://mybucket.s3.amazonaws.com/video.mp4" download="video.mp4">Download</a>

这在 Chrome 和 IE 中完美运行。从以下问题中,我了解到 Firefox 希望启用 CORS 以允许下载属性跨源工作:

HTML5 download attribute not working when downloading from another server, even when Access-Control-Allow-Origin is set to all (*)

我已使用以下技术在我的 S3 存储桶上启用了 CORS:

http://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-cors-configuration.html

这是我的 CORS 政策:

<CORSConfiguration>
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Firefox 仍然不想下载视频。任何帮助、提示或建议将不胜感激。谢谢。

【问题讨论】:

  • 你得到什么错误?请分享屏幕截图或复制并粘贴这些错误。
  • 当我使用 Firefox 点击下载链接时,mp4 视频会在新标签页中打开而不是下载。

标签: html amazon-web-services firefox amazon-s3


【解决方案1】:

您的 CORS 政策需要 Authorization 标头。将此更改为通配符。

在 AllowedHeader 中更改为 &lt;AllowedHeader&gt;*&lt;/AllowedHeader&gt;

【讨论】:

    【解决方案2】:

    您需要做几项检查,

    确保内容类型为application/octet-stream。默认情况下,除非您更改它,否则它是相同的。

    Firefox 处理 mp4 文件的方式不同,

    1. Enter about:config in the address bar
    2. Hit Enter
    3. Click I’ll be careful, promise!
    4. In the Search field, enter media.windows-media-foundation.enabled
    5. Double-click the True in the media.windows-media-foundation.enabled result to change it to False
    6. Close the browser tab
    

    然后firefox应该下载文件。

    参考:

    https://jdrch.wordpress.com/2013/10/01/how-to-prevent-firefox-from-playing-direct-link-mp4-files-in-the-browser/

    希望对你有帮助。

    【讨论】:

    • 感谢您的帮助。但是要求所有用户更改他们的 Firefox 配置不是一种选择。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2014-07-03
    • 2011-04-25
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 2020-09-06
    相关资源
    最近更新 更多