gpt4 book ai didi

python - 自动设置boto内容类型

转载 作者:太空宇宙 更新时间:2023-11-03 18:09:04 25 4
gpt4 key购买 nike

我有以下上传代码:

key.set_contents_from_filename(content)
key.set_acl(acl)

我不知道我在这里收到的文件类型,但有没有办法自动设置内容类型?

最佳答案

boto 库会自动尝试使用 Python mimetypes.guess_type 函数猜测 mime 类型,但这主要取决于从文件名中猜测。如果您想显式提供 mime 类型,可以通过在上传文件之前设置 content_type 属性来实现:

key.content_type = 'text/html'
key.set_contents_from_filename(content)

这能回答你的问题吗?

关于python - 自动设置boto内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26310267/

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