Is It Possible to Use Amazon Cloudfront URLs for Attachments Using Paperclip
1 answer
A little late, but never too late for people looking for an answer.
Upload your pictures to S3, as usual, set s3_permissions
to private so that they don't have public access via S3. Install s3_host_alias
, so paperclip uses this host by requesting the url for the attachment and then just sign that url.
You can use both signed URLs and signed cookies. For example, with a stone cloudfront-signer
:
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
See https://github.com/leonelgalan/cloudfront-signer#usage for details . Disclaimer, I am the permanent custodian of this gem.
+3
source to share