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

hi... using libapreq1 i'm able to upload multiple files with the following code:
foreach my $upload ($r->upload()) { my $upload_fh = $upload->fh; my $contents; while(<$upload_fh>) { $contents .= $_; } close($upload_fh); # write $contents to the file here... }
since i switched to libapreq2 i keep getting the folowing error:
Can't locate object method "fh" via package "form_field_name (perhaps +you forgot to load "form_field_name"?)
does any one know what's happening? not much info available out there.. thanks

Replies are listed 'Best First'.
Re: libapreq2 upload problem
by shmem (Chancellor) on May 19, 2008 at 22:15 UTC

    From the documentation of Apache2::Request:

    upload
    $req->upload() $req->upload($name)
    With no arguments, this method returns an APR::Request::Param::Table object in scalar context, or the names of all Apache2::Upload objects in list context.

    So, your $upload loop variable contains just a string (the name of an Apache2::Upload object). The string is no object proper, so you can't $upload->fh. Not having used myself anything mod_perl or Apache2::whatever - perhaps the following works:

    foreach my $upload ($r->upload()) { my $upload_fh = $r->upload($upload)->fh; my $contents; while(<$upload_fh>) { $contents .= $_; } close($upload_fh); # write $contents to the file here... }

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: libapreq2 upload problem
by TOD (Friar) on May 20, 2008 at 03:52 UTC
    as shmem said: it's always a good advice to read the fine manual. ;-)
    --------------------------------
    masses are the opiate for religion.