Paperclip S3 expiring_url with styles and SSL

comments 3
programming / rails

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.

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:

Now calling my expiring image URL with a style and over https is just:


  1. Wow, thanks man!
    I got stuck on the part where I had to get my documents back in my app from S3, when in private mode.
    I should give it some more testing, but it seems to work fine!

  2. Santuxus says


    Thanks for that solution! I had this patch in one of my projects, but it has stopped working after paperclip version update. Here is the code that works with the latest one:

    module Paperclip
    module Storage
    module S3
    def expiring_url(time = 3600, style = default_style)
    s3_object(style).url_for(:read, :expires_in => time, :secure => true)

Leave a Reply

Your email address will not be published.