How upload images asynchronously
I'm using Ruby on Rails 3 deployed at heroku. Now I have working fine a multiple image attachment using paperclip and amazon s3 for storage. But, when I submit the form, I have to wait too long time. For this reason I would upload the images asynchronously, using Ajax. Any example or tip? Thanks!
UPDATE: There is something that I don't understand. When you are filling the form of Post (for example) that have a multiple image attachment, the Post isn'开发者_JAVA技巧t created until you submit the form, then it don't have an ID. The Images belongs_to Post througt the post_id, then: How the plugin Jquery Uploader or Uploadify can save the images asyncronaly?
Asynchronous file uploading (with progress indication) via XMLHttpRequest isn't yet supported by all browsers, but the best jQuery plugin I've come across to do it is jQuery-File-Upload (demo here). It works with Chrome, Safari, Firefox, Opera, and MSIE, although MSIE doesn't yet have support for progress indication, unfortunately. The uploader is for all file types by default, but you can limit it to images.
Hopefully in future all browsers will be able to do this via AJAX, though at the moment you'll have to use Flash for completely cross-browser support.
I made the paperclip_upload gem. With this gem you can:
- Upload your file to an endpoint
POST /api/uploads
for example. This will return an identifier like this:{ "identifier": "9j3gp54p" }
- You can repeat step 1 all you want (using ajax, as you said in 2011 :P)
- You can send all the upload_identifiers in a lighter POST to
/api/attachments
for example. The gem will do the rest...
Check the README
精彩评论