in reply to CGI.pm and Large File Transfers

CGI.pm always saves uploads to a temporary file. It gives the program a filehandle to the temporary file. It does have a size limit defined in $POST_MAX. You may need that to -1 (unlimited) or a large positive size. Also, uploads are disabled by default with CGI.pm; this is controlled by the $DISABLE_UPLOADS variable.

Where did you find the upload_hook callback? I have never heard of it and can't find it in CGI.pm.

Replies are listed 'Best First'.
Re: Re: CGI.pm and Large File Transfers
by Avox (Sexton) on Mar 15, 2004 at 22:17 UTC
    The more I think about this challenge, the less I think the http solution will work and still be reliable (http certainly was not designed for it).

    As for upload_hook, I found it in the CGI.pm page on CPAN.org:

    You can set up a callback that will be called whenever a file upload is being read during the form processing. This is much like the UPLOAD_HOOK facility available in Apache::Request, with the exception that the first argument to the callback is an Apache::Upload object, here it's the remote filename.
    $q = CGI->new(); $q->upload_hook(\&hook,$data); sub hook { my ($filename, $buffer, $bytes_read, $data) = @_; print "Read $bytes_read bytes of $filename\n"; }

    If using the function-oriented interface, call the CGI::upload_hook() method before calling param() or any other CGI functions:
    CGI::upload_hook(\&hook,$data);

    This method is not exported by default. You will have to import it explicitly if you wish to use it without the CGI:: prefix.
      HTTP is just as reliable and fast as FTP. More reliable since there is only one connection instead of the separate data connection with FTP so less firewall worries. And you don't have to worry about a separate server with different authentication.

      Also, if you don't need other form fields (including the filename), then you can do a POST with the file content as the body. The receiving CGI would not use CGI.pm to parse the upload but read the body directly and save it to disk. The filename would have to be constructed by some other mechanism.