Saturday, July 15, 2006

AJAX File Uploader

In an administrative interface of my Photo Gallery I'm using XMLHttpRequest to send all the information about picture being uploaded to a server and check its validity. (I used synchronous mode because at the time I programmed it all the AJAX heap wasn't there yet). I wanted to upload files with the help of XMLHttpRequest without page reloading, but I couldn't find a way to do that. There were some proprietary IE solutions and proprietary Mozilla solutions, but no common one. To upload file, HTML form must set ENCTYPE="multipart/form-data" (a default value is "application/x-www-form-urlencoded") and it seems that XMLHttpRequest cannot do that.
The solution I found was to check everything and send a data to server using XMLHttpRequest without page reloading, then to upload a picture using conventional FORM POST operation inside an IFRAME.
It looks like that there is nothing new that and this Indian guy uses similar approach with his "AJAX File Uploader" class.

Although.... let's investigate all results of corresponding Google search.