views:

412

answers:

1

I'm trying to serve static files for download in a django application, I figured that I'd put the static files in /media/files and have Apache set the content-type header to application/octet-stream (the files to download are going to be word files but I'll work out the details later).

To do this I activated mod_headers and then in the apache config did this:

<Location "/media/files">
    Header set Content-Type "application/octet-stream"
</Location>

After doing this I restarted apache and tried a sample file but it doesn't work, I still get text/plain in the content type and the browser does not prompt me to download anything.

By the way I know it is recommended to use a different web server for static files but I don't have much control on the server I'm going to deploy, it has to be only Apache with mod_python.

+1  A: 

There could be any number of problems (it takes a lot more information than you've provided to trace down some apache config problems) but here are some thoughts:

  • Are you absolutely certain this snippet is being applied to the right files (e.g., if there are multiple virtual servers, and you stuck this in the wrong one, well..)
  • Do you have rewriting going on that might prevent this from being seen as a match?
  • Are you setting the Content-Type header elsewhere?
  • Do you have content arbitration going on? Depending, that could override anything you do in the headers.

One thing you might try is to add some other header and see if it comes back. Also, try doing the request yourself with telnet or elsewise reducing the number of things between you and the server. Use the log files. They are there to help you. Good luck.

MarkusQ
Thanks, mostly I was asking because I'm new to web dev and thought there might be something obviously wrong but now that I know what I'm doing is in theory correct I'll get to debugging.
Marcos Marin