Skip to content

Commit

Permalink
Merge pull request #726 from oda-hub/mimetype-one-file
Browse files Browse the repository at this point in the history
gzip-compressed mimetype if download one compressed file
  • Loading branch information
burnout87 authored Jan 9, 2025
2 parents a45dccd + 8f44325 commit 718ff2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cdci_data_analysis/flask_app/dispatcher_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,17 +1168,20 @@ def download_file(self, from_request_files_dir=False):
if file_name is None:
file_name = file_list[0] if len(file_list) == 1 else 'download.tar.gz'
return_archive = self.args.get('return_archive', 'True') == 'True'
mimetype = 'application/x-gzip-compressed' if return_archive and len(file_list) == 1 else None
# otherwise, for one file, the mimetype of the uncompressed file is determined, and gz only affects Content-Encoding
# but Content-Encoding header isn't set if as_attachment=True

tmp_dir, target_file = self.prepare_download(
file_list, file_name,
return_archive=return_archive,
from_request_files_dir=from_request_files_dir)
try:
return send_from_directory(directory=tmp_dir, path=target_file, attachment_filename=target_file,
as_attachment=True)
as_attachment=True, mimetype=mimetype)
except Exception as e:
return send_from_directory(directory=tmp_dir, filename=target_file, attachment_filename=target_file,
as_attachment=True)
as_attachment=True, mimetype=mimetype)
except RequestNotAuthorized as e:
extract_job_monitor = True
if not hasattr(self, 'scratch_dir') or self.scratch_dir is None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"celery",
"redis",
"pyjwt",
"marshmallow",
"marshmallow<3.24",
"black>=22.10.0",
"bs4",
"GitPython",
Expand Down

0 comments on commit 718ff2d

Please sign in to comment.