always guess the same filetype
authorBoris Bobrov <breton@cynicmansion.ru>
Thu, 12 Jul 2018 10:50:54 +0000 (12:50 +0200)
committerBoris Bobrov <breton@cynicmansion.ru>
Thu, 12 Jul 2018 10:50:54 +0000 (12:50 +0200)
mediagoblin/api/views.py

index b25300f0854dca95cb1a94558d260e6686efd849..dfa9dfa22099d22883ee19f2a017178144f85548 100644 (file)
@@ -119,8 +119,11 @@ def uploads_endpoint(request):
         if "X-File-Name" in request.headers:
             filename = request.headers["X-File-Name"]
         else:
-            filename = mimetypes.guess_all_extensions(mimetype)
-            filename = 'unknown' + filename[0] if filename else filename
+            filenames = sorted(mimetypes.guess_all_extensions(mimetype))
+            if not filenames:
+                return json_error('Unknown mimetype: {}'.format(mimetype),
+                                  status=415)
+            filename = 'unknown{0}'.format(filenames[0])
 
         file_data = FileStorage(
             stream=io.BytesIO(request.data),