在S3上使用boto库

2024-05-17 16:10:49 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法更改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文档时,我只能找到一种方法将一个密钥复制到另一个bucket中,但是在这种情况下,我需要文件保持在同一个bucket中,只需移动位置(即change key)。谢谢您。在


Tags: 文件thetokeyimageclibucketis
1条回答
网友
1楼 · 发布于 2024-05-17 16:10:49

只需将对象复制到同一个bucket并删除原来的bucket:

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()

相关问题 更多 >