From ae2b1ac00ff3309e1c7259b5da32123615494cae Mon Sep 17 00:00:00 2001 From: Brian Moe <brian.moe@ligo.org> Date: Thu, 31 Jan 2013 13:49:28 -0600 Subject: [PATCH] Download/mimetype for web page urls. Issue 713 --- gracedb/api.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gracedb/api.py b/gracedb/api.py index 6cbde6296..6064ca3fc 100644 --- a/gracedb/api.py +++ b/gracedb/api.py @@ -631,8 +631,14 @@ def download(request, graceid, filename=""): response = HttpResponseNotFound("File not readable") elif os.path.isfile(filepath): # get an actual file. - response = HttpResponse(open(filepath, "r"), content_type="application/octet-stream") - response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(filename) + content_type, encoding = VersionedFile.guess_mimetype(filepath) + content_type = content_type or "application/octet-stream" + # XXX encoding should probably not be ignored. + response = HttpResponse(open(filepath, "r"), content_type=content_type) + if content_type == "application/octet-stream": + response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(filename) + if encoding is not None: + response['Content-Encoding'] = encoding elif not filename: # Get list of files w/urls. rv = {} -- GitLab