Avatar of pnoeric
pnoericFlag for United States of America

asked on 

how does gmail start file upload once a file is selected?

check out gmail-- when you attach a file, after you select the file on your drive, you can keep working (NOT submit the form) and gmail is uploading the file... after a moment, it removes the prompt entirely and just shows the file as uploaded.

how're they doing this? I'm looking for some specifics, ideally some extremely stripped down basic code showing how it all comes together, so I can implement it in my app.

thanks.
Web Languages and StandardsJavaScript

Avatar of undefined
Last Comment
pnoeric
Avatar of bradley2u
bradley2u

I don't think they are actually grabbing the file until the message is sent.  This doesn't answer your questions at all, but i just tested with my gmail account with a very large attachment and a small attahcment (2 emails) and when I click "send" the large attachment took much longer than the smaller attachment to actually send and redirect back to the inbox.

Avatar of pnoeric
pnoeric
Flag of United States of America image

ASKER

Try it with just the two small files. You'll see it.

1. Compose new message
2. Attach small file #1
(optional, attach small file #2)
3. Tab down to message area
4. Type a message, or just sit there
5. Watch closely and a moment later, your attachments will have magically uploaded themselves.
Avatar of scrathcyboy
scrathcyboy
Flag of United States of America image

It is the HTML file upload feature -- see these for examples of HTML file upload that you can use anywhere

www.cs.tut.fi/~jkorpela/forms/file.html
www.quirksmode.org/dom/inputfile.html
www.w3.org/TR/device-upload
ww.tizag.com/phpT/fileupload.php

The part you don't see is that the page submits to a server script, like PHP, ASP, or JSP, and it is that server file that sends the email with the attached file -- it is easy to do, once you get through it the first time !
Avatar of pnoeric
pnoeric
Flag of United States of America image

ASKER

@scrathcyboy -- sorry, what?

The issue is not that it lets you upload a file-- sheesh, that's like HTML 101.

The issue is that it PERFORMS the upload BEFORE you submit the form.

Please try the steps I listed above... that's what I want to understand.
Avatar of scrathcyboy
scrathcyboy
Flag of United States of America image

You don't understand -- you are fooled by the interface, as are many people.
When you pick a file, it is uploading it while the little hourglass spins around.  You think nothing is happening, but it is, the file is being uploaded while you watch the spinning wheel, it is just that the page is not being refreshed, and you took the bait, didn't you?  Revisit HTML 101 a la google, Ebay and all other major sites.  You need to learn up on DHTML 101 if you are to "get smart".
Avatar of pnoeric
pnoeric
Flag of United States of America image

ASKER

Ok, so I guess we're back to my original question-- can you give me some specifics? Are they monitoring that field to see when the file is chosen? What tells the browser to start sending the file to the server without the form being submitted?

I look at the four links you supplied-- the first talked about the basic HTTP file upload which I know about, the second talked about how to style the input field (which is clever but has nothing to do with what I'm asking about, as far as I can tell), the third talks about HTTP upload again and the last link was some sample code for handling file uploads when an HTTP form is submitted. Nothing new or unusual.

I'm not trying to be troublesome here, @scrathcyboy -- just trying to understand how this one specific trick is executed. It's a bit more tricky than standard HTTP file uploads, since the form is never submitted... right? Am I missing something?
ASKER CERTIFIED SOLUTION
Avatar of mreuring
mreuring
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mreuring
mreuring
Flag of Netherlands image

Oh, I forgot to mention, they do this on the 'onChange' event of the file-input...
Avatar of pnoeric
pnoeric
Flag of United States of America image

ASKER

aha-- that's what I was tryin' to figure out. mucho thanks. E
Avatar of pnoeric
pnoeric
Flag of United States of America image

ASKER

brilliant, that's the secret I was trying to uncover. thanks. E
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo