Friday, April 8, 2016

Rails Tools: Paperclip and Cloudinary, brought together

Need a low-cost viable solution for storing and serving image file attachments in your Rails application? Read on...

For a number of implementations, I have used thoughtbot's Paperclip gem to manage my Rails models' file attachments. It provides sizing and scaling via Imagemagick and is simple to get up and running quickly. For file storage, I found the paperclip-dropbox gem as an excellent way to hook up a free Dropbox account to store and manage a few files.

Unfortunately, not only is that gem no longer activity maintained (with ominous warnings across the homepage now), but this solution also doesn't work quite so well for images; particularly, serving images to display online. And the jump in price point from Dropbox to AWS or similar wasn't really something I wanted to take on. So, I needed something cost-effective that was good at serving images. For that purpose, I ran across Cloudinary.

Cloudinary is an image and video cloud-based management solution which is very fast, easy to manage, and has a usable free tier. It also has some awesome directives that can be used for on-the-fly image transformation in just about any way you can imagine, such as sizing, scaling, coloring, overlaying, and much more. Not only that, but Cloudinary is also Rails-friendly, coming with a Rails gem as well as a direct integration to CarrierWave, which is essentially an alternative to Paperclip.

Using Cloudinary and CarrierWave together is a great solution for many, and for those happy to do that, Cloudinary provides detailed instructions on getting integrated. However, for me, migrating from my Paperclip/Dropbox solution to CarrierWave/Cloudinary was a task I wasn't too keen on performing. So, I decided to build the missing link, bringing together Paperclip and Cloudinary.


Gem Version


The paperclip-cloudinary gem adds "cloudinary" as a new storage option for Paperclip, and dropping that in as the storage option along with the downloadable configuration file from a Cloudinary account will have your images stored in Cloudinary in minutes. From there, you can use Cloudinary's cool features to further manipulate your images in views. Or not, it's up to you from there.

Bottom line, if you're sticking with Paperclip, but want a better free-to-low-cost alternative to Dropbox for serving images, try paperclip-cloudinary.

--
Carl Scott
Software Developer, Solertium Corporation
View Carl Scott's profile on LinkedIn View Carl Scott's ohloh profile