batmonk has asked for the wisdom of the Perl Monks concerning the following question:

When you upload files using multi-part forms, you normally receive no feedback as the file is being sent to the server.

Is is possible to write a Perl CGI script that accepts the file upload in increments, so you can print messages that the user sees?

If so, where should I look for more details? I checked lwpcook, the CGI faqs, and a few different search engines to no avail. An example would be ideal, but I'll take RTFM if you can tell me which manual I should be flipping.

Replies are listed 'Best First'.
(crazyinsomniac) Re: File upload progress?
by crazyinsomniac (Prior) on Feb 09, 2001 at 09:27 UTC
    Interesting question.

    I've seen one example, well kind of.

    Indigoperl comes with a web-based package managment tool. Anyway, while you're downloading a new package in a forked process, the browser is being refreshed every 3 to 5 seconds, and is displaying a file that is constantly being updated with the progress, until the program is done writing to that temporary file, ie the package has been downloaded.

    As for a file upload in increments, i guess it's possible, if you can figure out a way to read the file via cgi incrementally, and figure out where you left off.

    I really don't see this as being beneficial to the user at all. It would take more time to upload that image (via cgi only), because the client would be sending the entire image from the start, not having any way of knowing where your script left off, aside from bytecount.

    It sounds very much like you're trying to develop a server-side type of resumable upload(like resumable-download), but this would still require some type of program, asides from a browser, on the client side.

    "Disclaimer: Don't blame, it came from inside the void"
    #--------------------------------------------- crazyinsomniac

      I'm not so sure.

      Perl supports while loops; HTTP tells you the length of the content. Certainly there's a way to parse that into digestible (and reportable) chunks...isn't there?

      And, to be perfectly frank, TCL confuses me. Hence, my request for shared wisdom. Certes, other members of our Order have posed the same question. Haven't they?

        You're not listening.
        There is no way to accomplish this via a the Common Gateway Interface(a Browser). Meaning client/server communication via a browser is turn based. The browser says something, the server says something back. And then
        You CAN accomplish this, but it'll require your clients download some kind of plugin or program.

        I also asked a few monks in the c/b, and chromatic pointed out, like i've been saying, that there is no way having the server send status of the request to the client, within the constraints of the HTTP spec.

        Which brings me back to what i said before, you can do it if your clients download some kind of program or plugin.

        I will mention the method that the IndigoPerl folks used, but that would require you have 2 browser windows open, or some kind of frames(HTML frames) configuration, but it still wouldn't provide for resuming(incremental turn based upload like you suggested).

        chromatic mentioned something like that being possible with Netscape, if the Netscape folks are able to finish it, but don't hold your breath.

        I would like to apologize in advance to chromatic if i misunderstood or miscommunicated anything.

        Perl for IE via ActivX sounds like an option, but i don't know too many casual users who have perl installed.

        Another option might be some kind of java applet, or even a Macromedia Flash(yes it is possible) plugin.

        "Disclaimer: Don't blame, it came from inside the void"
        #--------------------------------------------- crazyinsomniac

Re: File upload progress?
by cajun (Chaplain) on Feb 09, 2001 at 09:07 UTC
Re: File upload progress?
by epoptai (Curate) on Feb 09, 2001 at 15:25 UTC
    I realize you want something like the download dialog but it's overstating to say there's no feedback. Both of the most popular browsers have two indicators of assurance that something's happening during uploads (throbber and status). Things like upload status (and authentication) are supposed to be, and are better left to be handled by the client in the customary fashion.
Re: File upload progress?
by Anonymous Monk on Mar 27, 2001 at 17:44 UTC
    Excuse my bad english :-) I think the best way is to use a flash movie. This movie ask to another CGI script the current size of your temp file. The flash movie don t need refresh to dialog with the script, just asking every 4 seconds, so the uploading have nearly the same speed !! But if you want write a pourcent progress you must know the size of the file to upload before the uploading. I don't know if how to do this !
      google search for megaupload, its a sourceforge project and does exactly what you want