[英]Update a static webpage in S3 bucket with Python/boto3
I tried to find another article with my question but I failed.我试图找到另一篇关于我的问题的文章,但我失败了。
My end goal is to upload an html file into an S3 bucket that is configured to host a static webpage.我的最终目标是将 html 文件上传到配置为托管静态网页的 S3 存储桶中。 I have tried with:
我试过:
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
s3.upload_file(local_file, bucket, s3_file)
and和
with open("index.html", "rb") as f:
s3.upload_fileobj(f, bucket, "index.html")
With both approaches, I successfully upload the html file.通过这两种方法,我成功上传了 html 文件。 Nonetheless, when I access the URL instead of displaying the html file, it downloads it.
尽管如此,当我访问 URL 而不是显示 html 文件时,它会下载它。
I can verify that the S3 bucket is configured to host a webpage and to display the file with the same name like the one I upload using Python.我可以验证 S3 存储桶是否配置为托管网页并显示与我使用 Python 上传的文件同名的文件。 When I upload the file manually from my folder, it works as expected.
当我从我的文件夹手动上传文件时,它按预期工作。 When I push the file using Python instead of displaying it, it downloads it as mentioned above.
当我使用 Python 推送文件而不是显示它时,它会如上所述下载它。
Has anyone experienced this before?有谁之前经历过这个吗? Is the 2 x functions I tried not appropriate for the work I need to do?
我尝试的 2 x 函数是否不适合我需要做的工作? Do you think there is any misconfiguration on the S3 bucket?
您认为 S3 存储桶上有任何配置错误吗?
Thanks in advance,提前致谢,
Based on the comments, the problem was incorrect/lack of text/html
content type for the objects uploaded.根据评论,问题是上传的对象不正确/缺少
text/html
内容类型。 The solution was to add it.解决方案是添加它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.