Rails 4 and Paperclip with S3 + Cloudfront

It’s been over two years since I have implemented Paperclip, the awesome image attachment gem,┬áinto a Rails app. The basic setup is still very easy and clean to do, as is the initial setup to get S3 storage working.

But what’s not well documented is how to use Cloudfront to serve up your image attachments rather than pulling them from S3. Thanks to this helpful answer on stack overflow, and a little digging into the code of Paperclip itself, it turns out to be trivial to implement. All you need to do is setup your url and s3_host_alias properly in your configuration files. Here’s what my production.rb config file now looks like for Paperclip:

 

Enjoy!

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *