Shrine Rails demo
This is a Rails demo for Shrine. It allows the user to create albums and attach images. The demo shows an advanced workflow:
- User selects one or more files
- The files get asynchronously uploaded directly to S3 and a progress bar is displayed
- The cached file data gets written to the hidden fields
- Once the form is submitted, background jobs are kicked off to process the images
- The records are saved with cached files, which are shown as fallback
- Once background jobs are finished, records are updated with processed attachment data
- User marks photos for deletion and submits
- Deletion starts in background, and form submits instantly
- Background job finishes deleting
This asynchronicity generally provides an ideal user experience, because the user doesn't have to wait for processing or deleting, and due to fallbacks they can be unaware of background jobs.
Direct uploads and backgrounding also have performance advantages, since your app doesn't have to receive file uploads (as files are uploaded directly to S3), and the web workers aren't blocked by processing, storing or deleting.
In production environment files are uploaded directly to S3, while in development and test environment they are uploaded to the app and stored on disk. The demo features both single and multiple uploads.
To run the app you need to setup the following things:
$ brew install imagemagick
Install the gems:
$ bundle install
Have SQLite installed and run the migrations:
$ rake db:migrate
Put your Amazon S3 credentials in
.envand setup CORS.
# .env S3_BUCKET="..." S3_REGION="..." S3_ACCESS_KEY_ID="..." S3_SECRET_ACCESS_KEY="..."
Once you have all of these things set up, you can run the app:
$ rails server