From 8e5b7f633910de7e1429f02f0661fcbe311600fb Mon Sep 17 00:00:00 2001 From: Boris Bobrov Date: Thu, 12 Jul 2018 12:50:54 +0200 Subject: [PATCH] always guess the same filetype --- mediagoblin/api/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mediagoblin/api/views.py b/mediagoblin/api/views.py index b25300f0..dfa9dfa2 100644 --- a/mediagoblin/api/views.py +++ b/mediagoblin/api/views.py @@ -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), -- 2.25.1