From: Romain Porte Date: Sat, 11 Nov 2017 17:29:54 +0000 (+0100) Subject: Change API filename upload using custom header X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f2b4760bd50d4ad6ec5899e90f655c2f4cf0884a;p=mediagoblin.git Change API filename upload using custom header When uploading a file using the API its same is always going to be 'unknown.', which is not good looking for file urls. This patch proposes a custom header named 'X-File-Name' that allows to specify a file name using an API client. This changeset was tested with a local OAuth1 client. --- diff --git a/mediagoblin/api/views.py b/mediagoblin/api/views.py index 74181fde..b25300f0 100644 --- a/mediagoblin/api/views.py +++ b/mediagoblin/api/views.py @@ -115,8 +115,13 @@ def uploads_endpoint(request): ) mimetype = request.headers["Content-Type"] - filename = mimetypes.guess_all_extensions(mimetype) - filename = 'unknown' + filename[0] if filename else filename + + 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 + file_data = FileStorage( stream=io.BytesIO(request.data), filename=filename,