Merge pull request #13789 from mvdbeek/fix_slow_downloads

[22.01] Fix slow download of large files
This commit is contained in:
David López
2022-04-25 19:07:31 +02:00
committed by GitHub
2 changed files with 11 additions and 2 deletions
+8 -1
View File
@@ -2,6 +2,7 @@
API operations on the contents of a history dataset.
"""
import logging
from io import IOBase
from typing import (
Any,
cast,
@@ -248,7 +249,13 @@ class FastAPIDatasets:
):
"""Streams the preview contents of a dataset to be displayed in a browser."""
extra_params = get_query_parameters_from_request_excluding(request, {"preview", "filename", "to_ext", "raw"})
display_data, headers = self.service.display(trans, history_content_id, history_id, preview, filename, to_ext, raw, **extra_params)
display_data, headers = self.service.display(
trans, history_content_id, history_id, preview, filename, to_ext, raw, **extra_params
)
if isinstance(display_data, IOBase):
file_name = getattr(display_data, "name", None)
if file_name:
return FileResponse(file_name, headers=headers)
return StreamingResponse(display_data, headers=headers)
@router.get(
@@ -469,7 +469,9 @@ class FastAPIHistoryContents:
while maintaining approximate collection structure.
"""
archive = self.service.get_dataset_collection_archive_for_download(trans, id)
return StreamingResponse(archive.get_iterator(), headers=archive.get_headers())
if archive.upstream_mod_zip:
return StreamingResponse(archive.response(), headers=archive.get_headers())
return StreamingResponse(archive.get_iterator(), headers=archive.get_headers(), media_type="application/zip")
@router.post(
'/api/histories/{history_id}/contents/{type}s',