使用 boto,在 s3 上已存在的文件上设置 content_type
我正在使用 django 存储和 s3boto 后端。根据此问题, http://code.larlet.fr/django-storages/issue/5/s3botostorage-set-content-type-header-acl-fixed-use-http-and-disable-query-auth- by 我有一堆文件(全部),其内容类型为“application/octet-stream”。鉴于我有一个
实例,如何设置 content_type?
In [29]: a.file.file.key.content_type
Out[29]: 'application/octet-stream'
In [30]: mimetypes.guess_type(a.file.file.key.name)[0]
Out[30]: 'image/jpeg'
In [31]: type(a.file.file.key)
Out[31]: <class 'boto.s3.key.Key'>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建文件后,无法修改与该文件关联的内容类型(或任何其他元数据)。但是,您可以在服务器端复制文件并在此过程中修改元数据。以下是 github 上的要点,应该会有所帮助:
https://gist.github.com/1791086
内容:
米奇
There is no way to modify the content type (or any other metadata) associated with a file after it has been created. You can, however, copy the file on the server side and modify the metadata in the process. Here is a gist on github that should help:
https://gist.github.com/1791086
Contents:
Mitch