Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of Zepto.js, of, and I'm a Ruby on Rails core alumnus. With Amy Hoy I'm building cheerful software, like Noko Time Tracking and Every Time Zone and write books like
   Want me to speak at your conference? Contact me!

FUD revisited (1): Can you upload files with AJAX?

September 30th, 2005

The short answer is: No.

The long answer is: You can’t, because AJAX get/post data is gathered via JavaScript, and JavaScript has no way at getting at local file contents (for security reasons).

But you can use AJAX to get information on the running upload, as long as your framework has functions that give information on current uploads; and your webserver doesn’t buffer upload data.

In Ruby on Rails that works like this: If you enable the UploadProgress module, Rails stores information about the progress in the session, so while the upload is doing its thing, you can poll the server via an AJAX call and get nice status information. The Upload itself is made via a “traditional” HTML upload form to a hidden IFRAME (the helpers will do all this hard work for you transparently!).

See Sean Treadway’s demo and articles about this.