Add file extension to locally-stored media
What does this MR do?
When using internal file storage (not S3), files are saved without a file extension. This prevents them from being served by Nginx, as the latter has no support for MIME sniffing. The response Content-Type
header is derived solely from the file extension, which obviously doesn't work if the file is extension-less. This PR attaches a file extension to all local files, matching the behavior of the S3 file storage.
Practically speaking, this will have no impact on most instances. Only non-standard configurations will benefit, such as those using the reverse-proxy to serve files without involving the backend. Low-end servers are most likely to use this configuration, as it greatly reduces latency and CPU/IO overhead by removing an entire hop from the network path.
Contribution Guidelines
By submitting this merge request, you agree to follow our Contribution Guidelines
-
I agree to follow this project's Contribution Guidelines -
I have made sure to test this merge request
Merge request reports
Activity
added enhancement label
- Resolved by dakkar
the
FileServerService
does not set thecontent-type
header to exactly the type of the file:reply.header('Content-Type', FILE_TYPE_BROWSERSAFE.includes(file.mime) ? file.mime : 'application/octet-stream');
so that we don't send
application/pdf
ortext/xml
or stuff like that.I suspect we want NGINX to do the same thing, so maybe we don't want to add an extension to the filename if the type is not "browser safe"
(I may also be talking about completely unrelated stuff, let me know)
added 1 commit
- 0de93c2b - only attach file extension for browser-safe file types
mentioned in commit 565c9877