diff --git a/lib/galaxy/webapps/galaxy/api/datasets.py b/lib/galaxy/webapps/galaxy/api/datasets.py index ce7a0a2efd1..569049ba4f3 100644 --- a/lib/galaxy/webapps/galaxy/api/datasets.py +++ b/lib/galaxy/webapps/galaxy/api/datasets.py @@ -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( diff --git a/lib/galaxy/webapps/galaxy/api/history_contents.py b/lib/galaxy/webapps/galaxy/api/history_contents.py index a9c9ff61277..8010a58ee03 100644 --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -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',