WebFaction
Community site: login faq

Hi,

I've got a django webapp for serving dynamic content and a static/cgi webapp for static content. I'd like to configure the static app to force the download of pdf and mp3 files instead of allowing the browser to automatically "handle" them.

  1. The reason I'm giving users a pdf is so they can "download" it. Opening it in the browser just adds one more step and can confuse some people.
  2. The same thing for mp3 files. I already have a flash mp3 player built into the site so people can listen online. I want them to have the option of downloading the mp3 file, but just giving them a link to the file lets the browser start playing the file with whatever application happens to be registered ... again, not the idea.

This site suggests doing this by using the FilesMatch directive in apache and changing the mime type to octet stream.

http://www.thingy-ma-jig.co.uk/blog/06-08-2007/force-a-pdf-to-download

However, I've tried this in the http.conf file of my django/apache server as well as in a .htaccess file of my static webapp with no luck. Does anyone have any suggestions on how to accomplish this?

Thanks,

Scott

asked 01 Jul '11, 19:36

seversol
313
accept rate: 0%


The directives should work within an .htaccess file if your media app is 'Static/Cgi/PHP" type. Does this issue occur in more than one browser? What was the exact code you pasted into the .htaccess file?

permanent link

answered 01 Jul '11, 19:53

johns
5.4k312
accept rate: 23%

edited 01 Jul '11, 19:55

This is what I tried in .htaccess at the root of the ~/webapps/htdocs dir.

<filesmatch "\.(?i:pdf)$"=""> 
    ForceType application/octet-stream 
    Header set Content-Disposition attachment 
</filesmatch> 

I also tried similar lines in the http.conf file. I also added the following line in http.conf

LoadModule headers_module    modules/mod_headers.so

I have a feeling I don't really understand how the servers processes are controlled. I noticed that even when I shutdown my django/apache server it had no effect on my static/cgi server. I guess that's probably an apache process that's shared between many users?

Thanks for the feedback!

(01 Jul '11, 22:51) seversol

hmm ... that ="" doesn't appear in the regex in my file ...

(01 Jul '11, 22:55) seversol

To get a better idea of how the server is set up you can use this image,

http://docs.webfaction.com/user-guide/_images/inside-the-server.png

Could you possibly provide the URL this is occurring at so we can take a look at it directly? You may also submit a support ticket and we can look directly.

(01 Jul '11, 23:24) johns

Thanks, I did submit a support ticket and here was the solution that ended up working for me. The following was added to .htaccess in the root of my static app:

<filesmatch "\.(pdf|mp3)$"="">
    AddType application/octet-stream .pdf
    AddType application/octet-stream .mp3
</filesmatch>

... again the ="" does not appear in the first line ( ...(pdf|mp3)$">) as I pasted it in. I'm not sure why the forum app is interpreting it that way.

Thanks for the help!

(03 Jul '11, 16:16) seversol

I just had this same problem and the final solution didn't work.

I had to use

<filesmatch "\.(pdf|mp3)$">
    Header set Content-Disposition attachment 
    AddType application/octet-stream .pdf
    AddType application/octet-stream .mp3
</filesmatch>
permanent link

answered 24 Nov '11, 16:00

elpargo
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×9
×5
×2

question asked: 01 Jul '11, 19:36

question was seen: 4,979 times

last updated: 24 Nov '11, 16:00

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM