gpt4 book ai didi

amazon-s3 - 将 .html 文件上传到 S3 静态网站托管存储桶会导致在浏览器中下载 .html 文件

转载 作者:行者123 更新时间:2023-12-04 14:24:15 24 4
gpt4 key购买 nike

我有一个启用了“静态网站托管”的 S3 存储桶。如果我通过 AWS 控制台将 html 文件上传到存储桶,html 文件将成功打开。如果我使用 AWS CLI 上传文件,为什么会下载文件而不是显示在浏览器中?

第一个文件可在此处获得:https://s3.amazonaws.com/test-bucket-for-stackoverflow-post/page1.html

第二个文件可在此处获得:https://s3.amazonaws.com/test-bucket-for-stackoverflow-post/page2.html

我在 AWS 控制台中上传了第一个文件,第二个文件是使用以下命令上传的:

     aws s3api put-object --bucket test-bucket-for-stackoverflow-post  --key page2.html --body page2.html

最佳答案

第二个文件因其“Content-Type” header 而被下载。该 header 是:

Content-Type: binary/octet-stream

如果你想让它显示,应该是:

Content-Type: text/html

尝试将 --content-type text/html 添加到您的 put-object 命令。

引用:https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object.html

关于amazon-s3 - 将 .html 文件上传到 S3 静态网站托管存储桶会导致在浏览器中下载 .html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49053714/

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