| Apache2-ASP documentation | Contained in the Apache2-ASP distribution. |
Apache2::ASP::UploadHandler - Base class for Handlers that process file uploads
Don't use this clas. Subclass Apache2::ASP::MediaManager instead.
This package provides the Apache2::ASP environment with the ability to process file uploads while they are happening. Trigger points are exposed that are called at specific times during a file upload.
The $Upload argument is an Apache2::ASP::UploadHookArgs object.
Called just before upload_hook() is called for the first time. If you need to do
any kind of setup or double-checking, this is the time to do it.
The $Upload argument is an Apache2::ASP::UploadHookArgs object.
Called just after upload_hook() is called for the last time. If you need to do
any kind of cleanup or redirect the user, this is the time to do it.
The $Upload argument is an Apache2::ASP::UploadHookArgs object.
Called each time Apache reads in a chunk of bytes from the client during the upload.
It's possible that some bugs have found their way into this release.
Use RT http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP to submit bug reports.
Please visit the Apache2::ASP homepage at http://www.devstack.com/ to see examples of Apache2::ASP in action.
John Drago mailto:jdrago_999@yahoo.com
Copyright 2007 John Drago, All rights reserved.
This software is free software. It may be used and distributed under the same terms as Perl itself.
| Apache2-ASP documentation | Contained in the Apache2-ASP distribution. |
package Apache2::ASP::UploadHandler; use strict; use base 'Apache2::ASP::HTTPHandler'; our $LastUpdate; our $LastPercent; #============================================================================== sub upload_start { my ($s, $context, $Upload) = @_; return; return unless $Upload; # Store the upload information in the Session for external retrieval: $LastUpdate = time(); $LastPercent = $Upload->{percent_complete} || 0; my $uploadID = $s->_args('uploadID'); $context->session->{"upload$uploadID$_"} = $Upload->{$_} foreach grep { $_ !~ m/data/ } keys(%$Upload); $context->session->save; }# end upload_start() #============================================================================== # The logic *we* need is already taken care of by the UploadHook's RegisterCleanup, # so we can just leave this stub for subclassing: sub upload_end { my ($s, $context, $Upload) = @_; 1; }# end upload_end() #============================================================================== sub upload_hook { my ($s, $context, $Upload) = @_; return; # Since this method may be called several times per second, we only # want to save the Session state once per second: my $Diff = time() - $LastUpdate; my $PercentDiff = $Upload->{percent_complete} - $LastPercent; if( $Diff >= 1 || $PercentDiff >= 5 ) { my $uploadID = $s->_args('uploadID') || ''; # Store everything in the session except for the data # (since that could be too large to serialize quickly): $context->session->{"upload$uploadID$_"} = $Upload->{$_} foreach grep { $_ !~ m/data/ } keys(%$Upload); $context->session->save; $LastUpdate = time(); $LastPercent = $Upload->{percent_complete}; }# end if() }# end upload_hook() #============================================================================== sub _args { my ($s, $key) = @_; my %args = map { split /\=/, $_ } split /&/, $ENV{QUERY_STRING}; return $args{$key}; }# end _args() 1;# return true: __END__