S3 中使用 Boto3 的 AWS 内容类型设置 [英] AWS Content Type Settings in S3 Using Boto3

查看:42
本文介绍了S3 中使用 Boto3 的 AWS 内容类型设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Amazon 的 Boto3 SDK 用于 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.

这篇关于S3 中使用 Boto3 的 AWS 内容类型设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆