如何使用Rails保护图像? [英] How to secure images with Rails?
问题描述
我的rails应用程序中有一个图库,该图库仅需要将某些图像显示给特定的已登录用户.我现在正在使用Paperclip进行图像处理,但是它将所有图像保存在任何人都可以使用的公用文件夹中.
I have a gallery in my rails app that needs to only allow certain images to be shown to specific, logged in users. I am using Paperclip for image processing now, but it saves all images in a public folder available to anyone.
请注意,如果有更好的方法,我不必使用Paperclip,并且我已经安装了登录系统.我只需要一种将图像放置在非公开位置的方法,但是仍然能够根据需要提供这些图像.
Note that I don't have to use Paperclip if there is a better way, and I already have the login system in place. I just need a way to place the images in a non-public location, but still be able to serve them as needed.
是否可以仅将这些图像提供给经过身份验证的用户?
Is it possible to only allow these images to be served to authenticated users?
推荐答案
此处您可以找到如何更改上传图片的路径.如果您这样做了.您需要创建一个为这些静态文件提供服务的控制器.
Here you can find how to change the path of the uploaded pictures. If you have done this. You need to create a controller which serves these static files.