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


I'm trying to use CGI's upload hook feature to keep track of the progress of large file uploads. According to the docs,

The $use_tempfile field is a flag that lets you turn on and off's use of a temporary disk-based file during file upload. If you set this to a FALSE value (default true) then param('uploaded_file') will no longer work, and the only way to get at the uploaded data is via the hook you provide.

I want to turn off temp files and handle the data myself. Unfortunately, when I set this value to 0, my hook does not seem to ever get called.

Here's some code which works:

# override query object creation so we can install # our hook at instantiation sub cgiapp_get_query { my $self = shift; my $q = CGI->new( sub { $self->_ul_hook( @_ ) } ); return $q; } sub _ul_hook { my $self = shift; my ( $filename, $buffer, $bytes ) = @_; print STDERR "$filename: $bytes\n"; }

This code works fine and my hook gets called, but it creates a temporary file which I don't want.

When I change the constructor to this,

my $q = CGI->new( sub { $self->_ul_hook( @_ ) }, undef, 0 );

...the hook does not get called. (At least, there's no evidence of it in the error log.)

Thanks for any help.

Update: It also appears to fail if I explicitly set the third parameter to 1. Apparently it only works with the third parameter unspecified, but I don't want the default behavior. :(