Question

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 in this case, I need the file to stay in the same bucket, just move position (i.e., change key). Thank you.

Was it helpful?

Solution

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top