Nov 1 2007

Upload Files Like Gmail

This entry is part 2 of 3 in the series Gmail Architecture

Now we can see ajax everywhere. Most of the famous websites are now enabled ajax for providing faster navigation and browsing speed.

If you are a gmail user, the thing you noticed very attractively should be the file attaching part of the email composing window.

If you wait for sometime you can see, your file gets automatically uploaded without submitting the whole form. This is not Ajax. Because XMLHttpRequest (XHR) is not supporting multipart/form-data.

You can use iframe for this purpose by pointing the target of form submission towards the iframe (you can place it as hidden style=”display:none”)

<form target=”iframename” action=”upload.php”>

You can write javascript at the upload.php end, you can change the file uploaded updations just like ajax

Sample code for this “Ajax File Upload” or Gmail-Like File Upload is here :
File-Upload-Like-Gmail.rar

Winrar logo

Thanks and Regards

Sajith.M.R

Series Navigation«Gmail ArchitectureGmail Chat Implementation»

11 Comments on this post

Trackbacks

  1. Gmail Architecture 1 « Dogfeeds——IT Telescope wrote:

    [...] Gmails file uploading is another interesting thing. I already posted ajax file uploading : http://www.sajithmr.com/upload-files-like-gmail/ [...]

    June 12th, 2009 at 12:08 pm
  1. Rochak Chauhan said:

    AJAX is very handy and effective tool for any Rich Web Application. However it has few limitations too:

    1) It can not make a remote call to another server.
    2) It can not post anything to the server other than text.

    But don’t let this effect you ! All this can still be done with a little work around.

    For more details: http://www.rochakchauhan.com

    December 11th, 2007 at 1:31 pm
  2. Victor said:

    I have soe problem about upload file in hidden iframe, would you pls give me some suggestion????

    I have make a form and submit it through AJAX, and everything is work. And now I would like to provide a file upload function. I would like to keep my form submit in AJAX way, but file upload must upload through form.submit().

    The problem is when I use ajax to post a form while the file is still under uploading, the ajax request would ignore the file upload. So what can I do to make it wait untill the file is fully upload?

    April 9th, 2008 at 12:45 pm
  3. Sajith M.R said:

    XMLHTTP Request does not support multipart data. So upto now (April 2008) there is no file uploading via ajax is possible. And form javascript , you can get the intermediate information of a file uploading. So mere javascript cant create a progress bar or anything with this file uploading. You can use applet or some activeX script for this purpose. Then what you can do with ajax is after uploading , you can make the needful changes.

    April 9th, 2008 at 1:05 pm
  4. Nishant Mittal said:

    Sajith, Excellent articles. I like the step by step writing style.
    One interesting thing about GMAIL file upload is that it handles the browser’s back button elegantly. Most Iframe based file upload solutions create an entry into the browsers history (BACK/FORWARD button). IE is very easy to trick but Opera is very unforgiving. GMAIL however works fine even with OPera. I dont know how they manage to do it. do you?

    May 23rd, 2008 at 1:47 am
  5. cc said:

    I test your script and I meet the following :
    - as far the input point to hiddenframe how I will escape from form using html redirect tag ? - other suggestion ?
    Thanks.

    August 18th, 2008 at 2:57 pm
  6. Sudhin said:

    I tried with your script and reach almost to the target…..i think i can..

    October 6th, 2008 at 10:19 am
  7. uchup said:

    hmm.. i still do not understand about use ajax..

    December 11th, 2008 at 8:20 am
  8. Jamie said:

    Thanks for this. Just one thing: it would be handy for non-Windows users if you could put up future downloads in a more conventional compression format, e.g. zip. (OS X users: download something like UnRarX to open this file).

    February 22nd, 2009 at 4:50 am
  9. saul said:

    very simple and usefull
    going to join it on my code igniter project
    great job

    March 13th, 2009 at 12:42 am
  10. manish said:

    it ir realy gud yar.
    gr8 work

    June 3rd, 2009 at 3:17 pm

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Recent Comments

  • Sajith M.R: Press shift and enter key for a new line in chat
  • Borellus: Nice little function there, I think I may try to use it at some point.
  • Abhishek: Can we have newline characters…. i want something like this Line 1 Line 2 Line 3
  • Joanne Cox: Thanks for sharing this; your input is appreciated and has made me change my opinion slightly. About the...
  • Saboor: hi i also want to implement a chatting like Gmail or FaceBook , please, email me the source code on...

Recent Posts