Skip to content

Improve file download capabilities#5129

Merged
kflemin merged 3 commits intodevelopfrom
5075/download-files-w-commas
Mar 3, 2026
Merged

Improve file download capabilities#5129
kflemin merged 3 commits intodevelopfrom
5075/download-files-w-commas

Conversation

@perryr16
Copy link
Copy Markdown
Contributor

@perryr16 perryr16 commented Nov 4, 2025

Any background context you want to provide?

Files with commas in their names (e.g., 12,props,eui,80.xlsx) were downloading as zero bytes from the dataset detail page. This only affected ImportFiles uploaded through the dataset upload endpoint.

For context, there are 6 'file' models that can be downloaded: ImportFile, BuildingFile, InventoryDocument, AnalysisOutputFile, AnalysisInputFile, and ResultFile. Of those, AnalysisOutputFile, AnalysisInputFile, and ResultFile are named internally and are not at risk of having an invalid name.

Downloading InventoryDocuments, BuildingFiles, and ImportFiles from the inventory detail page succeeded even if those files contained commas because Django's FileField automatically sanitizes filenames on upload.

What's this PR do?

Updates the media retrieve endpoint to serve directly through Django instead of nginx X-Accel-Redirect which cannot handle commas or special characters in the filename:

  • Simpler and more reliable code
  • A few hundred milliseconds slower for very large excel files, otherwise the delay should not be noticeable
  • Backwards compatible: should work with all existing ImportFiles

To prevent future issues, imported files are now sanitized on upload to remove problematic characters.

How should this be manually tested?

  • Upload an import file with commas in the filename, attempt to download it from the dataset detail (/data/<id>/).
  • For further testing, test ImportFile, InventoryDocument, and BuildingFile downloads from the inventory detail (/properties/<id>/) page. These downloads should already succeed on the develop branch.

What are the relevant tickets?

#5075

Screenshots (if appropriate)

@perryr16 perryr16 added the Bug label Nov 4, 2025
@kflemin kflemin merged commit bd7b32b into develop Mar 3, 2026
9 checks passed
@kflemin kflemin deleted the 5075/download-files-w-commas branch March 3, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants