Skip to content

Instantly share code, notes, and snippets.

@mattdennewitz
Created October 21, 2010 16:22
Show Gist options
  • Save mattdennewitz/638800 to your computer and use it in GitHub Desktop.
Save mattdennewitz/638800 to your computer and use it in GitHub Desktop.
s3 can stream a file to the user with a different filename
from boto.s3.connection import S3Connection
file_to_upload = "e434b232c2e4f70aa2819d708dfd30fb4cebcf6c.zip"
s3 = S3Connection(YOUR_AWS_ACCESS_KEY, YOUR_AWS_SECRET_KEY)
bucket = s3.get_bucket(YOUR_BUCKET_NAME)
# user will receive "mixtape.zip" instead of "e434b232c2e4f70aa2819d708dfd30fb4cebcf6c.zip"
s3_headers = {'Content-Disposition': "attachment; filename=mixtape.zip"}
mt_key = bucket.new_key(file_to_upload)
mt_key.set_contents_from_filename(/path/to/file_to_upload,
headers=s3_headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment