Commit 0c0a8971 by Vik Paruchuri

Work on uploading image submission to S3

parent d06f5f77
...@@ -87,7 +87,7 @@ def run_image_tests(image): ...@@ -87,7 +87,7 @@ def run_image_tests(image):
image_properties = ImageProperties(image) image_properties = ImageProperties(image)
return image_properties.run_tests() return image_properties.run_tests()
def upload_to_s3(string_to_upload, keyname): def upload_to_s3(file_to_upload, keyname):
''' '''
Upload file to S3 using provided keyname. Upload file to S3 using provided keyname.
...@@ -101,8 +101,8 @@ def upload_to_s3(string_to_upload, keyname): ...@@ -101,8 +101,8 @@ def upload_to_s3(string_to_upload, keyname):
k = Key(bucket) k = Key(bucket)
k.key = keyname k.key = keyname
k.set_metadata("Content-Type", 'images/png') k.set_metadata('filename', file_to_upload.name)
k.set_contents_from_string(string_to_upload) k.set_contents_from_file(file_to_upload)
public_url = k.generate_url(60*60*24*365) # URL timeout in seconds. public_url = k.generate_url(60*60*24*365) # URL timeout in seconds.
return True, public_url return True, public_url
......
...@@ -27,6 +27,8 @@ import open_ended_image_submission ...@@ -27,6 +27,8 @@ import open_ended_image_submission
from datetime import datetime from datetime import datetime
from PIL import Image
log = logging.getLogger("mitx.courseware") log = logging.getLogger("mitx.courseware")
# Set the default number of max attempts. Should be 1 for production # Set the default number of max attempts. Should be 1 for production
...@@ -281,7 +283,26 @@ class OpenEndedChild(object): ...@@ -281,7 +283,26 @@ class OpenEndedChild(object):
@return: @return:
""" """
success = False success = False
image_ok = run_image_checks(image) image = Image.open(image_data)
try:
image_ok = open_ended_image_submission.run_image_tests(image)
success = True
except:
pass
if success:
image_key = image_data.name + datetime.now().strftime("%Y%m%d%H%M%S")
try:
success, public_url = open_ended_image_submission.upload_to_s3(image_data, image_key)
success = True
except:
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment