Created
July 28, 2014 14:55
-
-
Save kirang89/db73e22199c587d69dcf to your computer and use it in GitHub Desktop.
Uploading a file to Amazon S3 using boto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cStringIO | |
from boto.s3.connection import S3Connection | |
from boto.s3.key import Key | |
def s3upload(filename, extension, file): | |
conn = S3Connection('AWS_ACCESS_KEY', 'AWS_SECRET_KEY') | |
k = Key(conn.get_bucket('<bucket name>')) | |
k.key = filename | |
k.set_metadata("Content-Type", file.mimetype) | |
fp = cStringIO.StringIO(file.read()) | |
k.set_contents_from_file(fp) | |
k.set_acl("public-read") | |
fp.close() | |
return "https://s3.amazonaws.com/<bucket name>/{}.{}".format(filename, extension) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment