在S3上使用boto库

3
有没有一种方法可以更改S3文件的键?例如,我想要做的就是相当于:
>>> from boto.s3.key import Key
>>> k=Key(bucket)
>>> k.key='cli-images/image-thumb.jpg' # this is the original key
>>> k.key='cli-images/moved/image-thumb.jpg' # this is the key I want to change it to
>>> k.save()

在查看boto文档时,我只找到了一种将密钥复制到另一个存储桶的方法,但在这种情况下,我需要文件留在同一个存储桶中,只是更改位置(即更改密钥)。谢谢。

1个回答

11

将对象复制到同一个存储桶中,然后删除原始对象:

from boto.s3.key import Key
k=Key(bucket)
k.key='cli-images/image-thumb.jpg'
k.copy('bucketname', 'cli-images/moved/image-thumb.jpg')
k.delete()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接