如何更改元数据在Amazon S3中的对象上 [英] How to change metadata on an object in Amazon S3
问题描述
如果您已经上传的对象到Amazon S3的桶,你如何改变使用API的元数据?这是可能做到这一点在AWS管理控制台,但目前尚不清楚它如何通过编程完成。具体来说,我使用Python和阅读很明显,使用key.set_metadata只适用的在的对象,因为它只是影响本地字典创建。
If you have already uploaded an object to an Amazon S3 bucket, how do you change the metadata using the API? It is possible to do this in the AWS Management Console, but it is not clear how it could be done programmatically. Specifically, I'm using the boto API in Python and from reading the source it is clear that using key.set_metadata only works before the object is created as it just effects a local dictionary.
推荐答案
看来你需要覆盖的对象本身,使用PUT对象(复制)与 X-AMZ-元-directive:更换
头除了元数据。在博托,这可以这样进行:
It appears you need to overwrite the object with itself, using a "PUT Object (Copy)" with an x-amz-metadata-directive: REPLACE
header in addition to the metadata. In boto, this can be done like this:
k = k.copy(k.bucket.name, k.name, {'myKey':'myValue'}, preserve_acl=True)
请注意,任何元数据不包括在旧字典将被丢弃。因此,要preserve老的属性,你需要做的是这样的:
Note that any metadata you do not include in the old dictionary will be dropped. So to preserve old attributes you'll need to do something like:
k.metadata.update({'myKey':'myValue'})
k2 = k.copy(k.bucket.name, k.name, k.metadata, preserve_acl=True)
k2.metadata = k.metadata # boto gives back an object without *any* metadata
k = k2;
我几乎错过了这个解决方案,这是暗示在介绍到一个不正确的标题问题,这实际上是关于比这个问题的一个不同的问题:的现有S3对象的更改内容处置
这篇关于如何更改元数据在Amazon S3中的对象上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!