Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Trouble with browser file upload for large files

by Baz (Friar)
on May 28, 2002 at 21:16 UTC ( #169912=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I'm using -
<FORM NAME=UPLOADFORM ENCTYPE="multipart/form-data" ACTION="/cgi-bin/u +pload.cgi" METHOD="POST>
to upload code to my server. This upload is then read using the following, which is typical for uploads
while (my $bytesread = read($filesource, my $buffer,1024)) { print OUTFILE $buffer; }
THe problem I'm having is that the upload times out for large files (in the order of 3 Megs) - I'm getting the usual "Cannot Find Server Message" after about 5 mins. This upload works for other users on the server, so I guess the upload speed is the main issue here - I'm using a 56K modem. I searched the net and found a similar complaint from another perl programmer. He said he had even raised the application timeout to 3000 seconds ( something I know nothing about but can at least appreciate) and this didn't help matters. I tried uploading the file to my tripod a/c using their browser upload facility and got the same timeout after a number of minutes - so their site seems to have a similar fault. Anyone know whats going wrong and what I can do to fix it.

Replies are listed 'Best First'.
Re: Trouble with browser file upload for large files
by chromatic (Archbishop) on May 28, 2002 at 21:20 UTC
    Send something to the browser every x seconds. You'll probably want to turn off output buffering, if you do.
Re: Trouble with browser file upload for large files
by vladb (Vicar) on May 28, 2002 at 21:23 UTC
    I'm not entirely sure if this would be the optimal solution in your case, but the way I think this might work is if you were to fork off a child process to handle the file writing part. This would allow you to free up the main process to finish rendering the page to the web client and thereby avoid the time out message.

    The code might look something like this (not tested! :):
    if (!fork) { # doing stuff in child process... # open your file handle here while (my $bytesread = read($filesource, my $buffer,1024)) { print OUTFILE $buffer; } # you could also write to a 'status' file and display that back to t +he client ;) exit; } print $cgi->header(); print "Your upload is in process... see this status.html page for the +status (changes every once in awhile :)\n"; exit;

    $"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}
      I tried switching off output buffering by adding
      select(STDOUT); $| = 1;
      at the start of my code, and by putting
      print "."
      in the while loop (above) which is writing to the upload file. I though this would print dots during the course of the upload, but it doesn't, why not?
        try adding a newline:
        print ".\n";

        cLive ;-)


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://169912]
Approved by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2022-11-28 01:39 GMT
Find Nodes?
    Voting Booth?