Repository navigation
fix(export): save downloads under the file name sent by the server [DHIS2-22131] - #2301
Open
jason-p-pickering wants to merge 2 commits into
Open
jason-p-pickering wants to merge 2 commits into
jason-p-pickering wants to merge 2 commits into
Conversation
…HIS2-22131] Since exports are fetched first and saved from a blob URL (9661c61), the browser no longer sees the response's Content-Disposition header, so a compressed export was saved under the name taken from the request URL, e.g. dataValueSets.json for a ZIP archive. fetchAndDownload now reads the file name from Content-Disposition and passes it to locationAssign, which falls back to the URL-derived name when the header has none. This applies to all exports that use fetchAndDownload: data, event, metadata, metadata dependency and tracked entity. 🤖 AI Assisted
Contributor
|
🚀 Deployed on https://pr-2301--dhis2-import-export.netlify.app |
Addresses SonarQube rule S6594. 🤖 AI Assisted
|
Contributor
Author
|
@tomzemp or @Sharmyn28 feel free to close this once you fix this for real. |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes https://dhis2.atlassian.net/browse/DHIS2-22131
Problem
Since 101.5.0, a compressed export is saved under the uncompressed file name. For example, a data export with ZIP compression is saved as
dataValueSets.json, although the file is a ZIP archive.Commit 9661c61 changed exports to fetch the file first, so the app can show the server's error message, and then save it from a blob URL. A blob URL has no
Content-Dispositionheader, so the browser falls back to the link'sdownloadattribute, whichlocationAssignbuilds from the request URL. The server still sends the right name, for exampleattachment; filename="dataValues_2026-07-02_2026-10-02.json.zip", but the app no longer uses it.Change
fetchAndDownloadreads the file name from the response'sContent-Dispositionheader and passes it tolocationAssign.locationAssignuses that name for the download, and falls back to the name derived from the URL when there is none, as before.getFilenameFromContentDispositionhandlesfilename="...", an unquotedfilename=..., and the encodedfilename*=UTF-8''...form, which it prefers.This applies to every export that uses
fetchAndDownload: data, event, metadata, metadata dependency and tracked entity.Testing
locationAssignwith a given file name.fetchAndDownloadtest checks that the download link is named afterContent-Disposition. It fails without the change, getting the URL-derived name instead.helper.test.jspass, andd2-style check jspasses.Content-Dispositionnames for ZIP, GZip and uncompressed data exports. The app currently saves the ZIP export asdataValueSets.json.The backend counterpart, DHIS2-22126 (correct
Content-Typefor compressed data exports), is already merged in core.🤖 AI Assisted