Commit 82286628 authored by kaiyou's avatar kaiyou

Fix an issue when pasting complex URIs (with query string for instnace)

parent e1d949de
......@@ -34,9 +34,10 @@ def image_from_url(url):
def save_with_thumbnail(image, filename):
dest = "."
while os.path.exists(os.path.join(app.config["FULL_STORAGE"], dest)):
filename, ext = os.path.splitext(filename)
filename, _ = os.path.splitext(filename)
ext = image.format.lower()
random = binascii.hexlify(os.urandom(3)).decode('utf8')
dest = "%s-%s%s" % (filename, random, ext)
dest = "%s-%s.%s" % (filename, random, ext)
# Grab some configuration
full_file = os.path.join(app.config["FULL_STORAGE"], dest)
thumb_file = os.path.join(app.config["THUMB_STORAGE"], dest)
......
from tedimg import app, images
import flask
import urllib
import os
......@@ -27,10 +28,12 @@ def upload():
filename = os.path.basename(uploaded.filename)
elif url:
image = images.image_from_url(url)
filename = os.path.basename(url)
parsed = urllib.parse.urlparse(url)
filename = os.path.basename(parsed.path)
else:
return flask.render_template("error.html", message="Missing image.")
except Exception as error:
__import__("traceback").print_exc()
return flask.render_template("error.html", message="Could not store your image.")
# Save the image to a local file
result = images.save_with_thumbnail(image, filename)
......
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