Function to upload stuff to S3
This commit is contained in:
@@ -82,6 +82,27 @@ def run_image_tests(image):
|
||||
image_properties = ImageProperties(image)
|
||||
return image_properties.run_tests()
|
||||
|
||||
def upload_to_s3(string_to_upload, keyname):
|
||||
'''
|
||||
Upload file to S3 using provided keyname.
|
||||
|
||||
Returns:
|
||||
public_url: URL to access uploaded file
|
||||
'''
|
||||
try:
|
||||
conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
|
||||
bucketname = str(AWS_STORAGE_BUCKET_NAME)
|
||||
bucket = conn.create_bucket(bucketname.lower())
|
||||
|
||||
k = Key(bucket)
|
||||
k.key = keyname
|
||||
k.set_contents_from_string(string_to_upload)
|
||||
public_url = k.generate_url(60*60*24*365) # URL timeout in seconds.
|
||||
|
||||
return True, public_url
|
||||
except:
|
||||
return False, "Could not connect to S3."
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user