alex 18th May 2024 at 1:31pm
File serving was not very easy, because there is a relationship to the headers that I cannot solve now, and this is one of those issues where the effort put in trying to find a fix is more easily solved by working around it: instead of, as what I am trying now, display .pdf
files in the browser, I might as well serve everything as direct download.
Well, in fact the map
of nginx
easily solves this. I had a hard-coded add_header Content-Type
for .pdf
files, but this is much better. Just ensure the map
directive goes under http
and not server
, or the routes.
http {
[...]
map $request_uri $mime_type {
default "application/octet-stream";
~\.(pdf)$ "application/pdf";
~\.(mkv)$ "video/x-matroska";
~\.(ipynb)$ "application/x-ipynb+json";
}
[...]
server {
[...]
/route/ {
[...]
add_header Content-Type $mime_type;
}
}
}
Status | done |
---|---|
Priority | high |