Skip to content

Commit

Permalink
gzip-compressed mimetype if download one compressed file
Browse files Browse the repository at this point in the history
  • Loading branch information
dsavchenko committed Jan 8, 2025
1 parent a45dccd commit 78f5118
Showing 1 changed file with 5 additions and 2 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

0 comments on commit 78f5118

Please sign in to comment.