JGuizard
4/7/2017 - 9:16 AM

Upload a file to a s3 bucket

Upload a file to a s3 bucket

import boto
import boto.s3
import sys
from boto.s3.key import Key

AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''

bucket_name = "thecoach"
conn = boto.connect_s3(AWS_ACCESS_KEY_ID,
        AWS_SECRET_ACCESS_KEY)

#bucket = conn.get_bucket(bucket_name)
bucket = conn.create_bucket(bucket_name,
    location=boto.s3.connection.Location.DEFAULT)


testfile = "logo.png"
print 'Uploading %s to Amazon S3 bucket %s' % \
   (testfile, bucket_name)

def percent_cb(complete, total):
    sys.stdout.write('.')
    sys.stdout.flush()


k = Key(bucket)
k.key = 'recap/logo.png'
k.set_contents_from_filename(testfile,
    cb=percent_cb, num_cb=10)