public
Last active

Update the content-type of an existing key in S3 using boto

  • Download Gist
update_key.py
Python
1 2 3 4 5 6 7 8 9 10 11
import boto
 
s3 = boto.connect_s3()
bucket = s3.lookup('mybucket')
key = bucket.lookup('mykey')
 
# Copy the key onto itself, preserving the ACL but changing the content-type
key.copy(key.bucket, key.name, preserve_acl=True, metadata={'Content-Type': 'text/plain'})
 
key = bucket.lookup('mykey')
print key.content_type

Thanks, this helped me a lot dude.

Helped me too, thanks

Exactly what I was looking for. Thanks!

bucket.lookup(key_name) has been deprecated. Source Boto. Use bucket.get_key(key_name) instead.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.