使用Boto3在S3中进行AWS内容类型设置 [英] AWS Content Type Settings in S3 Using Boto3
问题描述
我正在尝试使用Amazon的 Boto3 SDK 将网页上传到S3存储桶中>用于Python.
I am trying to upload a web page to an S3 bucket using Amazon's Boto3 SDK for Python.
我在设置Content-Type
时遇到问题.除了我使用此代码指定的密钥外,AWS还在为Content-Type
创建一个新的元数据密钥:
I am having trouble setting the Content-Type
. AWS keeps creating a new metadata key for Content-Type
in addition to the one I'm specifying using this code:
# Upload a new file
data = open('index.html', 'rb')
x = s3.Bucket('website.com').put_object(Key='index.html', Body=data)
x.put(Metadata={'Content-Type': 'text/html'})
对于将Content-Type
设置为text/html
的任何指导,将不胜感激.
Any guidance of how to set Content-Type
to text/html
would be greatly appreciated.
推荐答案
Content-Type
不是 custom 元数据,而Metadata
则用于该元数据.它具有自己的属性,可以这样设置:
Content-Type
isn't custom metadata, which is what Metadata
is used for. It has its own property which can be set like this:
bucket.put_object(Key='index.html', Body=data, ContentType='text/html')
注意:.put_object()
可以设置的范围不仅限于Content-Type
.查看 Boto3文档休息.
Note: .put_object()
can set more than just Content-Type
. Check out the Boto3 documentation for the rest.
这篇关于使用Boto3在S3中进行AWS内容类型设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!