我正在使用Paperclip在Amazon S3上存储图像附件并通过Cloudfront交付它们。我环顾四周,无法找到与签名网址一起使用的示例来保护内容。我想知道这里有人知道怎么做吗?
谢谢,
伦纳德
答案 0 :(得分:3)
有点晚了,但对于寻找答案的人来说永远不会太晚。
像往常一样将照片上传到S3,将s3_permissions
设置为私有,这样他们就无法通过S3进行公开访问。设置s3_host_alias
,以便回形针在询问附件的网址时使用该主机,然后只需签署该网址。
您可以使用签名网址或签名Cookie。例如,使用cloudfront-signer
gem:
has_attached_file :photo,
s3_permissions: :private,
s3_host_alias: "dcx01yp1dg1u1.cloudfront.net"
# Now photo.url will point to dcx01yp1dg1u1.cloudfront.net instead of S3
Aws::CF::Signer.sign_url photo.url, expires: Time.now + 600
有关其他详细信息,请参阅https://github.com/leonelgalan/cloudfront-signer#usage。免责声明,我是这个宝石的当前维护者。