Re: Apache2::Request UPLOAD_HOOK and mod_perl Handler
"Fred Moyer" <[email protected]>
| Newsgroups | gmane.comp.apache.apreq |
|---|---|
| Message-ID | <[email protected]> |
Michael Michalowski Web.de wrote:
> hi,
>
> I've got a few questions about the UPLOAD_HOOK of Apache2::Request
> and the way implementing it. I'm not sure, whether this is the right
> mailinglist or not, so sorry if this is not the right one. ;-)
Apache2::Request is part of the libapreq package so this is the correct
list, but you could also ask this on the mod_perl list since
Apache2::Request is one of the primary modules for processing request
arguments.
http://perl.apache.org/maillist/modperl.html
> I'm trying to write a Perl Class which provides a handler() function
> for mod_perl. something like that:
>
> package InterRed::UploadLimiter;
>
> use strict;
> use Digest::MD5 qw(md5_hex);
> use CGI::Cookie;
>
> sub handler
> {
> my $r = shift;
> my $transparent_hook = sub {
> my ($upload, $data, $data_len, $hook_data) = @_;
> warn "$hook_data: got $data_len bytes for " . $upload->name;
> };
>
> my $req = Apache2::Request->new($r,
> UPLOAD_HOOK => $transparent_hook,
> );
> $req->parse();
>
> return Apache2::Const::OK;
> }
>
> 1;
> __END__
>
...
> Therefor I tried to register my handler like that in my apache config
> file:
>
> <IfModule mod_perl.c>
> # PerlFixupHandler InterRed::UploadLimiter
> # PerlChildInitHandler InterRed::UploadLimiter
> PerlHandler InterRed::UploadLimiter
> </IfModule>
>
> As you can see, I tried different Handler types, because I'm not sure
> which one is right to handle uploads (the upload must not be started
> at this time). I want the handler to control any kind of perl cgi
> script, which sends uploads to the server.
The closest correct handler is the PerlHandler, except that you referenced
Apache2::Request above, so I assume that you are using mod_perl2. You
need to use PerlResponseHandler there instead of PerlHandler.
PerlResponseHandler InterRed::UploadLimiter
See this link for a summary of the different handler phases.
http://perl.apache.org/docs/2.0/user/handlers/intro.html#mod_perl_Handlers_Categories
For an example of using the UPLOAD_HOOK, see this article I wrote on
perl.com:
http://www.perl.com/pub/a/2005/05/05/aggregation.html
It may be a bit overkill since you are new to this stuff, but it
demonstrates the necessary configuration and a complete handler for
processing uploaded data.
HTH,
Fred