simple remotipart alternative using async file upload instead of iframe trick?


I was using remotipart to get "remote: true" forms to upload images (using paperclip) and was working fine. However, we now have an iOS "App" that is just our website wrapped in a webview, and file uploads do not work here. I believe it has something to do with the webview mucking with iframes but not sure and we don't have access to the iOS code (it was from a thirdparty company). I found that jquery-file-uploader does work in the app since it uses async xhr file uploads, but there is no simple integration for this like remotipart where you can just drop it in and have all your "remote: true" forms start working. Is there any gem out there that does this? With jquery-fileupload-rails gem I have to do this to get the same functionality:

  1. Disable automatic upload
  2. Set the form to "remote: false", then override the form submit button (preventDefault) and call data.submit() manually, but only if the user chooses to upload an image, if not I let the default form action work.
  3. Handle validation error in the controller. If there is an error (like blank field) The image is not saved, but the path to the image is changed and when the form is reloaded with validation errors the image shows as missing instead of the original image, so I have to manually replace the image with the original in the controller in case of error. Also, ideally it would keep the file they specified instead of resetting the field, but not sure how to do this yet, so even if there is an error in another field, they have to re-select their file.

I have a complex form with several nested fields (that also accept image uploads) and also and "attachments" section that has dynamically added file fields. These dynamically added fields do not get picked up with the original call to .fileupload() when the form loads, so I have to call it again for each added file field, however this seems to not be working right now and causes the other images to not get uploaded...

Anyway, was wondering if there was an equivalent to remotipart that is a drop in fix for remote forms that uses xhr instead of iframe....

This video can help you solving your question :)
By: admin