Skip to content

Commit 45547ce

Browse files
committed
allow client to specify download name
1 parent aad6f1b commit 45547ce

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

server.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from mimetypes import guess_type
33
from sh import convert
44
from glob import glob
5-
from urllib import pathname2url
5+
from urllib import pathname2url, quote
66
from collections import defaultdict, OrderedDict
77
from functools import wraps
88
import EXIF, json, hmac, time
@@ -216,7 +216,12 @@ def getfileref():
216216
@require_token('filename')
217217
def fileget():
218218
"""Returns the file data of the file indicated by the query parameters."""
219-
return static_file(resolve_file(), root=settings.BASE_DIR)
219+
r = static_file(resolve_file(), root=settings.BASE_DIR)
220+
download_name = request.query.downloadname
221+
if download_name:
222+
download_name = quote(path.basename(download_name))
223+
r.set_header('Content-Disposition', "inline; filename*=utf-8''%s" % download_name)
224+
return r
220225

221226
@route('/fileupload', method='OPTIONS')
222227
def fileupload_options():

0 commit comments

Comments
 (0)