Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@garnaat
Created February 10, 2012 17:25
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save garnaat/1791086 to your computer and use it in GitHub Desktop.
Save garnaat/1791086 to your computer and use it in GitHub Desktop.
Update the content-type of an existing key in S3 using boto
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
@rod-dot-codes
Copy link

Thanks, this helped me a lot dude.

@tszming
Copy link

tszming commented Nov 12, 2013

Helped me too, thanks

@bsoist
Copy link

bsoist commented Feb 28, 2014

Exactly what I was looking for. Thanks!

@ganesshkumar
Copy link

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

@ZoomQuiet
Copy link

thanx for large help!
can copy self is very key idea ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment