JP Richardson
JP Richardson

Reputation: 39385

Set content-disposition on public file types in Rails?

I have some PDF files in a public rails folder. I want to set the response header "content-disposition" to "attachment". I know I can create a controller to read the files and set the header myself, but is there some general application wide setting that i can enable/configure?

Thanks in advance.

-JP

Upvotes: 3

Views: 1667

Answers (2)

Bob Aman
Bob Aman

Reputation: 33239

What cwninja said.

Assuming Apache as your front-end server:

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

application/octet-stream because application/pdf doesn't force a download in IE sometimes.

Upvotes: 2

cwninja
cwninja

Reputation: 9768

Rails/Rack never sees requests to your public folder, your front end web server should handle these. Assuming you are using Apache you could use this approach.

Failing that you can move the files out of the way and use either a rack middleware or a controller as mentioned to handle the request.

Upvotes: 2

Related Questions