如何使用Rails保护图像? [英] How to secure images with Rails?

查看:59
本文介绍了如何使用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.

例如:

是否可能只允许这些 要提供给身份验证的图像 用户?

Is it possible to only allow these images to be served to authenticated users?

是的,您只需要检查用户是否已登录负责该图像的控制器操作即可.

Yes, you just need to check if the user is logged in in the controller action responsible for the image.

这篇关于如何使用Rails保护图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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