开发者

Set content-disposition on public file types in Rails?

开发者 https://www.devze.com 2022-12-09 17:50 出处:网络
I have some PDF files in a public rails folder. I want to set the response header \"content-disposition\" to \"attachment\". I kn开发者_Python百科ow I can create a controller to read the files and set

I have some PDF files in a public rails folder. I want to set the response header "content-disposition" to "attachment". I kn开发者_Python百科ow 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号