in reply to Upload Progress Bar

I had to solve this exact problem about 6 months ago for an application that parsed uploaded files real time and fed back progress indicators to the user. There is a great description of how to do a search in progress out there by merlyn, but this situation is a bit different in that the main application window is handling the upload, and cannot be refreshed.

I did this in a mod_perl2 handler using Apache::Request, but you should be able to accomplish the same with cgi scripts. Upon the user clicking 'Upload', I used javascript to open a small status window which refreshed waiting for the presense of upload status data. Meanwhile the main window begins the upload process. An UPLOAD_HOOK (see a::r docs) subroutine measured the amount of bytes received from the client and wrote it to a status file which the monitor read.

Now, this worked very well for displaying the amount of bytes received from the user. As for determining the percentage of file uploaded, a::r provides the following useful method:

my $size = $upload->size;

However I did not find the size returned to be reliable when referenced from within the UPLOAD_HOOK subroutine. I suspect is determined once the file is fully uploaded. So I wasn't able to give the user a realistic estimation of when the file would be done uploading.

But I was able to parse the contents real-time, display the results to the user, and terminate the upload if the errors in the file exceeded a certain threshold, which got good feedback from the users. I got some flak from reviewers of the technique, but it worked very well. I was able to pass back to the user accurate information about where in the file errors were, which saved them a great deal of time.

HTH

Replies are listed 'Best First'.
Re^2: Upload Progress Bar
by Anonymous Monk on Dec 26, 2004 at 02:40 UTC
    Hey Red, Thanks a lot, thatīs exactly what I was looking for. Iīve visited CPAN and in fact I think it will do. But, tell me, I can run this module even without mod_perl? My host's server is Apache.

    The one thing that still remains a mystery to me is how to manage, and by how many scripts, the signals and the processing of the file. I still donīt know if I can have the same script that processes the file upload and processing, to check $upload->size, tell the status bar (in wich page?) the new status or to get lost as the upload ends.

    Other thing is the javascript. Iīm not very skilled in javascript. Can you send me your code, or some sample of it? I donīt have a clue of how to do it...

    Thank you very much!

    André

      For information on javascript check here.

      I had the upload handler write the byte count to a session file, and the monitor process which was opened through the javascript on the "Upload" button read from the same session.

      CGI.pm also has an upload_hook subroutine which you can use to do this - you don't explicitly need a::r. You might also want to take a look at Apache::UploadMeter , I was using mod_perl2 so I had to roll my own.