As you probably know reading our blog, Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. And we want to prove that again by presenting you a new toolkit. Shrine is a file attachments toolkit for Ruby applications.
Some highlights of Shrine:
- Modular design – the plugin system allows you to load only the functionality you need
- Memory friendly – streaming uploads and downloads make it work great with large files
- Cloud storage – store files on disk, AWS S3, Google Cloud, Cloudinary and others
- ORM integrations – works with Sequel, ActiveRecord, Hanami::Model and Mongoid
- Flexible processing – generate thumbnails on upload or on-the-fly using ImageMagick or libvips
- Metadata validation – validate files based on extracted metadata
- Direct uploads – upload asynchronously to your app or to the cloud using Uppy
- Resumable uploads – make large file uploads resumable by pointing Uppy to a resumable endpoint
- Background jobs – built-in support for background processing that supports any backgrounding library
A “storage” in Shrine is an object responsible for managing files on a specific storage service (disk, AWS S3, Google Cloud etc), which implements a generic method interface. Storages are configured directly and registered under a name in
Shrine.storages, so that they can later be used by uploaders.
The main method of the uploader is
#upload, which takes an IO-like object on the input, and returns a representation of the uploaded file on the output.
If you’re curious how it compares to other file attachment libraries, see the here.
Don’t miss a chance to find out about Rubyfmt, a Ruby autoformatter.