So, I'm working on an app where users can upload and manage photos with a bunch of industry specific metadata attached to them.
The Photo model has all this metadata in it, and I'm using Paperclip to attach the actual image file to the model and store the images on Amazon S3.
The user interaction currently works like this:
- A user clicks "Add Photo" and is taken to the "New Photo" page where he is presented a form.
- The first thing on the form is a file chooser. The user selects a file.
- Beneath this are several different fields of metadata for the user to fill out, so the user fills these out.
- The user hits submit, the file uploads and a new Photo object is created, the user is redirected to a different page.
So, the obvious improvement that I'd like to make is for the photo to actually upload at the beginning of this process so that there isn't such a noticeable delay between hitting submit and being redirected to the next page. It would also be nice to be able to show the user a thumbnail preview of their photo once it's done uploading, so that they can see the photo they're putting in metadata about as they fill in the form.
I figure I could make that happen if I split the image file into its own model, but I'd then be referring to the images like so:
@photo.attachment.file.url
instead of the simpler @photo.file.url
that I use now. I'd rather not "nest it" more deeply than I have to.
Also, splitting it into two models raises the issue of managing orphans, which I currently don't have to deal with.
So my questions are:
- Is there a good way - preferably not using Flash - to create this asynchronous upload behavior without splitting into two models, OR --
- If I must split the metadata and the file into two models, is there a way to get Paperclip to treat an attachment as its own model so that I can access it using
<modelname>.<paperclip_method>
instead of<model_name>.<attachment_attribute>.<paperclip_method>
?
I know that's a big question, so thank you very much in advance for your help!