Fix image upload problem in API
authorJessica Tallon <jessica@megworld.co.uk>
Fri, 4 Apr 2014 17:25:20 +0000 (12:25 -0500)
committerJessica Tallon <jessica@megworld.co.uk>
Tue, 22 Jul 2014 22:13:15 +0000 (23:13 +0100)
mediagoblin/federation/views.py
mediagoblin/media_types/image/__init__.py

index 5ae7754c0398424856075cb2e71fd569100518be..7107f4bcc63f7524176f727831da1abb5e245007 100644 (file)
@@ -1,5 +1,6 @@
 import json
 import io
+import mimetypes
 
 from werkzeug.datastructures import FileStorage
 
@@ -56,14 +57,17 @@ def uploads(request):
     request.user = requested_user[0]
     if request.method == "POST":
         # Wrap the data in the werkzeug file wrapper
+        mimetype = request.headers.get("Content-Type", "application/octal-stream")
+        filename = mimetypes.guess_all_extensions(mimetype)
+        filename = 'unknown' + filename[0] if filename else filename
         file_data = FileStorage(
             stream=io.BytesIO(request.data),
-            filename=request.args.get("qqfile", "unknown"),
+            filename=filename,
             content_type=request.headers.get("Content-Type", "application/octal-stream")
         )
 
         # Find media manager
-        media_type, media_manager = sniff_media(file_data)
+        media_type, media_manager = sniff_media(file_data, filename)
         entry = new_upload_entry(request.user)
         if hasattr(media_manager, "api_upload_request"):
             return media_manager.api_upload_request(request, file_data, entry)
index ae0bfd1110a32f11d3f8068216aac4ee34145ed9..7b9296fe24a9d7a01607e213afab5070105fe1ae 100644 (file)
@@ -72,7 +72,7 @@ class ImageMediaManager(MediaManagerBase):
         queue_file = prepare_queue_task(request.app, entry, file_data.filename)
         with queue_file:
             queue_file.write(request.data)
-        
+
         entry.save()
 
         feed_url = request.urlgen(