From 2c83ead644d706aadfd36d5a38e7b34ab13facea Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 26 May 2016 12:35:14 -0500 Subject: [PATCH] Issue #1063. Re-allow image uploads from form elements for issue uploads. --- webcompat/api/uploads.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/webcompat/api/uploads.py b/webcompat/api/uploads.py index 2a28c734a..a3d7c8534 100644 --- a/webcompat/api/uploads.py +++ b/webcompat/api/uploads.py @@ -17,6 +17,7 @@ from flask import request from io import BytesIO from PIL import Image +from werkzeug.datastructures import FileStorage from werkzeug.exceptions import RequestEntityTooLarge from uuid import uuid4 @@ -43,7 +44,10 @@ def __init__(self, imagedata): def to_image_object(self, imagedata): '''Method to return a Pillow Image object from the raw imagedata.''' try: - # Make sure we're being sent a base64 encoded image + # Is this a file upload (i.e., issue form upload)? + if isinstance(imagedata, FileStorage): + return Image.open(imagedata) + # Is this a base64 encoded image (i.e., bug report screenshot)? if (isinstance(imagedata, unicode) and imagedata.startswith('data:image/')): # Chop off 'data:image/.+;base64,' before decoding @@ -106,7 +110,9 @@ def upload(): Returns a JSON string that contains the filename and url. ''' - if 'image' in request.form: + if 'image' in request.files and request.files['image'].filename: + imagedata = request.files['image'] + elif 'image' in request.form: imagedata = request.form['image'] else: # We don't know what you're trying to do, but it ain't gonna work.