Skip to content

Commit

Permalink
Issue #1063. Re-allow image uploads from form elements for issue uplo…
Browse files Browse the repository at this point in the history
…ads.
  • Loading branch information
Mike Taylor committed May 26, 2016
1 parent c68f16c commit 2c83ead
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions webcompat/api/uploads.py
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2c83ead

Please sign in to comment.