我有以下上传代码:
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/