Using boto library on S3
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()
精彩评论