fixes the inability to upload non ascii filenames, werkzeug strips all non ascii...
authordunkyp <dunkyp@gmail.com>
Tue, 6 Nov 2012 17:47:48 +0000 (17:47 +0000)
committerRodney Ewing <ewing.rj@gmail.com>
Thu, 11 Jul 2013 19:52:05 +0000 (12:52 -0700)
cherry-picked from dunkyp. fixed conflicts and missing import.

mediagoblin/submit/views.py

index 64e6791b36a93081f98c2a262cece956642af3d9..0fe280f1d7185b61cfd28ce84ffec951d93af6ed 100644 (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)