I have a Django application and I use nginx to serve static content. Unfortunately, all registered MIME types get displayed in client browser, while I would like to give an ability to download the same content, along with usual behaviour. Say, I have JPEG file under /media/images/image01.jpg
and I want that nginx serves this file in usual way, with standard image/jpeg
header, but additionally I want the same image to be served by nginx with content-disposition: attachment
(effectively forcing content download) when accessed as, say, /downloads/images/image01.jpg
. Anybody can suggest a solution?
views:
643answers:
2
+4
A:
Make sure you have the http_headers_module compiled in. (should be by default, if it isn't in the core)
Use "add_header content-disposition attachment;"
I recommend using a url like "/download?file=/downloads/images/image01.jpg" combined with a rewrite rule to avoid some annoying bug later.
epochwolf
2009-02-09 15:02:11
Why and how would you use URL with query parameters? To give the file with wrong file name for the user?
iny
2009-02-09 15:17:49
Thank you, that's it.
zgoda
2009-02-09 15:57:14
The reason for using a url with query parameters is to tell nginx to only force a download when using /download?file={filename} By using a rewrite rule properly you can add the header and still run through the rest of the rules in nginx's config.
epochwolf
2009-02-09 19:01:07
It's possible to ommit the "file=" part of the url and use "/download?{filename}" instead. The format is arbitrary the goal is to somehow let nginx know you need a different header than normal.
epochwolf
2009-02-09 19:04:14