سؤال

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.

هل كانت مفيدة؟

المحلول

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()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top