Properly pass around S3 interface
This commit is contained in:
@@ -13,11 +13,6 @@ from urlparse import urlparse
|
||||
import requests
|
||||
from boto.s3.connection import S3Connection
|
||||
from boto.s3.key import Key
|
||||
#TODO: Settings import is needed now in order to specify the URL and keys for amazon s3 (to upload images).
|
||||
#Eventually, the goal is to replace the global django settings import with settings specifically
|
||||
#for this module. There is no easy way to do this now, so piggybacking on the django settings
|
||||
#makes sense.
|
||||
from django.conf import settings
|
||||
import pickle
|
||||
import logging
|
||||
import re
|
||||
@@ -221,7 +216,7 @@ def run_image_tests(image):
|
||||
return success
|
||||
|
||||
|
||||
def upload_to_s3(file_to_upload, keyname):
|
||||
def upload_to_s3(file_to_upload, keyname, s3_interface):
|
||||
'''
|
||||
Upload file to S3 using provided keyname.
|
||||
|
||||
@@ -237,8 +232,8 @@ def upload_to_s3(file_to_upload, keyname):
|
||||
#im.save(out_im, 'PNG')
|
||||
|
||||
try:
|
||||
conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
|
||||
bucketname = str(settings.AWS_STORAGE_BUCKET_NAME)
|
||||
conn = S3Connection(s3_interface['access_key'], s3_interface['secret_access_key'])
|
||||
bucketname = str(s3_interface['storage_bucket_name'])
|
||||
bucket = conn.create_bucket(bucketname.lower())
|
||||
|
||||
k = Key(bucket)
|
||||
|
||||
@@ -100,6 +100,7 @@ class OpenEndedChild(object):
|
||||
self.display_name = static_data['display_name']
|
||||
self.accept_file_upload = static_data['accept_file_upload']
|
||||
self.close_date = static_data['close_date']
|
||||
self.s3_interface = static_data['s3_interface']
|
||||
|
||||
# Used for progress / grading. Currently get credit just for
|
||||
# completion (doesn't matter if you self-assessed correct/incorrect).
|
||||
@@ -319,7 +320,7 @@ class OpenEndedChild(object):
|
||||
|
||||
try:
|
||||
image_data.seek(0)
|
||||
success, s3_public_url = open_ended_image_submission.upload_to_s3(image_data, image_key)
|
||||
success, s3_public_url = open_ended_image_submission.upload_to_s3(image_data, image_key, self.s3_interface)
|
||||
except:
|
||||
log.exception("Could not upload image to S3.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user