Skip to content
Snippets Groups Projects
Commit 0c0a8971 authored by Vik Paruchuri's avatar Vik Paruchuri
Browse files

Work on uploading image submission to S3

parent d06f5f77
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,7 @@ def run_image_tests(image):
image_properties = ImageProperties(image)
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.
......@@ -101,8 +101,8 @@ def upload_to_s3(string_to_upload, keyname):
k = Key(bucket)
k.key = keyname
k.set_metadata("Content-Type", 'images/png')
k.set_contents_from_string(string_to_upload)
k.set_metadata('filename', file_to_upload.name)
k.set_contents_from_file(file_to_upload)
public_url = k.generate_url(60*60*24*365) # URL timeout in seconds.
return True, public_url
......
......@@ -27,6 +27,8 @@ import open_ended_image_submission
from datetime import datetime
from PIL import Image
log = logging.getLogger("mitx.courseware")
# Set the default number of max attempts. Should be 1 for production
......@@ -281,7 +283,26 @@ class OpenEndedChild(object):
@return:
"""
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment