A current requirement is that assets uploaded to Amazon S3 must be accessed via SSL and use an expiring URL. Using an expiring url with Paperclip is extremely easy.
1 |
my_model.image.expiring_url(5) |
The problem is expiring_url doesn’t let you choose a style and doesn’t use https, which breaks our SSL site. To add the behaviour was an easy “hack”. I added the file /config/initializers/paperclip.rb with the following code:
1 2 3 4 5 6 7 8 9 10 11 12 |
module Paperclip module Storage module S3 def expiring_url(style = default_style, time = 3600) AWS::S3::S3Object.url_for(path(style), bucket_name, :expires_in => time, :use_ssl => true) end end end end |
Now calling my expiring image URL with a style and over https is just:
1 |
my_model.image.expiring_url(:original, 5) |