开发者

Using boto library on S3

开发者 https://www.devze.com 2023-04-04 10:00 出处:网络
Is there a way to change the key of an S3 file? For example, I want to be able to do the equivalent of:

Is there a way to change the key of an S3 file? For example, I want to be able to do the equivalent of:

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

In looking over the boto documentation, I could only find a way to copy a key to another bucket, but i开发者_如何学JAVAn this case, I need the file to stay in the same bucket, just move position (i.e., change key). Thank you.


just copy the object to the same bucket and delete the original one:

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

精彩评论

暂无评论...
验证码 换一张
取 消