Greetings,

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 CGI.pm'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. :(


In reply to CGI.pm's upload hook with tempfile off by friedo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.