【发布时间】:2021-03-02 18:42:08
【问题描述】:
我有一个使用 python 上传到 s3 的 html 文件。出于某种原因,s3 添加了一个系统定义的元数据,说明文件 Content-Type 是“binary/octet-stream”:
我需要将此值更改为“text/html”。我可以手动完成,但我希望在上传文件时自动完成。 我尝试了以下代码:
metadata = {
"Content-Type": "text/html"
}
s3_file_key = str(Path("index.html"))
local_file_path = Path("~", "index.html").expanduser()
s3 = session.resource("s3")
bucket = s3.Bucket(bucket_name)
with open(local_file_path, READ_BINARY) as local_file:
bucket.put_object(Key=s3_file_key, Body=local_file, Metadata=metadata)
但结果是该文件有 2 个元数据键:
我找不到任何有关如何更改系统定义的元数据的文档。
感谢您的帮助
【问题讨论】:
标签: python python-3.x amazon-s3 bots