阻止在 Rails 中直接下载图像
现在在 Rails 中做图片库。我想阻止从网页下载图像的直接访问。这是怎么做的?我正在使用回形针 gem 上传图像。请帮助我解决这个问题。
Now doing Image gallery in rails. I want to block the direct access of downloading image from web page.How do this thing?. I am using paperclip gem to upload image. Please Help me to resolve this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器需要访问该图像才能显示它;在某些时候,浏览器上的某些东西将可以直接访问图像。
您可以混淆图像的检索方式,但这基本上是您能做的最好的事情。您也许可以与推荐人一起玩小游戏。
不要禁用右键单击;这太令人恼火了。
The browser will need to have access to the image in order to display it; at some point something on the browser will have direct access to the image.
You can obfuscate how the image is retrieved, but that's basically the best you can do. You might be able to play minor games with the referrer.
Don't disable right-click; that's irritating.
我想您基本上是在寻找登录系统。确保图像由控制器提供服务,而不是由 nginx 或任何为您提供静态服务的东西提供服务。鉴于您正在使用 Paperclip,我认为情况已经如此。因此,实际上您只需要检查控制器内是否有登录用户,如果用户未登录,则返回 403 响应或其他内容。
You're basically looking for a login system, I assume. Make sure the image is served by a controller, not by nginx, or whatever is serving your statics. Given that you're using Paperclip, I assume this is already the case. So really you just need to check for a logged in user inside the controller, and return a 403 response or something if the user isn't logged in.