在Rails中设置公共文件类型的内容处置? [英] Set content-disposition on public file types in Rails?

查看:62
本文介绍了在Rails中设置公共文件类型的内容处置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Public Rails文件夹中有一些PDF文件.我想将响应标题"content-disposition"设置为"attachment".我知道我可以创建一个控制器来读取文件并自己设置标头,但是我可以启用/配置一些通用的应用程序范围设置吗?

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?

谢谢.

-JP

推荐答案

Rails/Rack从未看到对您的公用文件夹的请求,您的前端Web服务器应处理这些请求.假设您使用的是Apache,则可以使用

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.

这篇关于在Rails中设置公共文件类型的内容处置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆