Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


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. :(

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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2022-12-07 07:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found