I'm using carrierwave_direct and delayed_job with user uploaded images. The process is:
- User drag & drops or selects a file.
- File is uploaded to S3 directly using carrierwave_direct to do all the form signing etc.
- User is presented with a dialog to crop their image, the key (from carrierwave_direct) is passed in through a hidden field. At this point no record exists in the database, but a file is stored on S3. Should the user now move away from the page, we will have an abandoned / unattached file on S3 that does not belong to any model.
- If user completes the process, a record will be created and processing (cropping and creating several thumbnail versions) is done by a worker queue.
I had to make a delayed job that is put into the queue as soon as the file is uploaded. It will have a delay of several hours (or days). This job checks to see if the file exists, then checks through all recently created image records in the database to see if any are attached to that file. If not, it deletes the file.
Lastly, I wanted to make use of Carrierwave classes to handle all the Fog stuff, since I was using it anyway.
I could not find this anywhere, so here is my version. Leaving this here for people to come across in the future.
This is how I did it.