Skip to content

Instantly share code, notes, and snippets.

@chriskief
Created July 13, 2014 18:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskief/5b07a556378d7f21cc0f to your computer and use it in GitHub Desktop.
Save chriskief/5b07a556378d7f21cc0f to your computer and use it in GitHub Desktop.
from boto.s3.connection import S3Connection
connection = S3Connection('aws access key', 'aws secret key')
buckets = connection.get_all_buckets()
for bucket in buckets:
for key in bucket.list():
print('%s' % key)
if key.name.endswith('.jpg'):
contentType = 'image/jpeg'
elif key.name.endswith('.png'):
contentType = 'image/png'
else:
continue
key.metadata.update({
'Content-Type': contentType,
'Cache-Control': 'max-age=864000'
})
key.copy(
key.bucket.name,
key.name,
key.metadata,
preserve_acl=True
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment