fixes the inability to upload non ascii filenames, werkzeug strips all non ascii chars and returns an empty string. This checks if the filename contains non asciis and if it does generates a uuid for filename. Also the request version of filename is used for generating alternative title for upload

cherry-picked from dunkyp. fixed conflicts and missing import.
This commit is contained in:
dunkyp 2012-11-06 17:47:48 +00:00 committed by Rodney Ewing
parent 9609ddc0a6
commit 3aeca53c85

View File

@ -19,6 +19,7 @@ import mediagoblin.mg_globals as mg_globals
from os.path import splitext
import logging
import uuid
_log = logging.getLogger(__name__)
@ -53,6 +54,10 @@ def submit_start(request):
try:
filename = request.files['file'].filename
# If the filename contains non ascii generate a unique name
if not all(ord(c) < 128 for c in filename):
filename = unicode(uuid.uuid4()) + splitext(filename)[-1]
# Sniff the submitted media to determine which
# media plugin should handle processing
media_type, media_manager = sniff_media(
@ -63,7 +68,7 @@ def submit_start(request):
entry.media_type = unicode(media_type)
entry.title = (
unicode(submit_form.title.data)
or unicode(splitext(filename)[0]))
or unicode(splitext(request.files['file'].filename)[0]))
entry.description = unicode(submit_form.description.data)