diff --git a/gracedb/api.py b/gracedb/api.py index 6cbde6296bbd569463bb0d0b60aba0621cc0d3c7..6064ca3fca8e0a655e825426dc5ed01576b3a406 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 = {}