如何在Ruby on Rails中存储私人照片和视频 [英] How to store private pictures and videos in Ruby on Rails

查看:160
本文介绍了如何在Ruby on Rails中存储私人照片和视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户A应该能够上传图片。
  • 用户A应该能够设置隐私。 (Public或Private)。
  • 用户B不应该能够访问用户A的私人图像。



  • 我打算使用回形针处理上传。



    如果将图像存储在RAILS_ROOT / public / images下,任何能够猜出文件名称的人都可以访问这些文件。 (例如,访问 http://example.com/public/images/uploads/john /family.png

    我需要使用 img 标签显示图片,所以我不能放置除公共以外的文件。



    如何确保用户或组的图像不能被他人访问?

    (如果我不能用Paperclip来实现这个功能,有什么好的解决方法?)

    解决方案

    我会在后端使用Paperclip S3,将上传的文件设置为私有,然后使用查询字符串请求身份验证替代来为我的图像标记生成URL。

    http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTAuthentication.html


    Here's a story:

    • User A should be able to upload an image.
    • User A should be able to set a privacy. ("Public" or "Private").
    • User B should not be able to access "Private" images of User A.

    I'm planning to user Paperclip for dealing with uploads.

    If I store the images under "RAILS_ROOT/public/images", anyone who could guess the name of the files might access the files. (e.g., accessing http://example.com/public/images/uploads/john/family.png )

    I need to show the images using img tags, so I cannot place a file except public.

    How can I ensure that images of a user or group is not accessible by others?

    (If I cannot achieve this with Paperclip, what is a good solution?)

    解决方案

    I would have Paperclip use S3 on the back-end, set uploaded files to private, and then use "Query String Request Authentication Alternative" to generate the URLs for my image tags.

    http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTAuthentication.html

    这篇关于如何在Ruby on Rails中存储私人照片和视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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