Hello all,
I'm usually a quiet reader of this list (with great joy I might add), but I
think I could use a hint by now :)
After reading up on Apache2::Request and Apache2::Upload I quickly got my
upload code working as intended.
However - I would love to limit the max upload size for obvious reasons.
When I set the "POST_MAX" in my request object and upload above limit, I get
a dull looking white page with the text:
"Exceeds configured maximum limit".
So my question is: can I redirect to a custom page easily, or do I need to
handle it in a different way? I saw the UPLOAD_HOOK mentioned in the
documentation, but did not look into this yet. I guess this would be my next
logical step, but I would love to hear from you if you have an easier way to
do it in Mason. I don't really need any advanced progress bar nor handling
for the small text uploads I'm making :)
I already handle 403, 404 and 500 with custom ErrorDocuments, so even a
redirect to that would be a good start.
Included in this mail I've put snippets of my handler, code, and HTML form.
Thank you in advance for any hints
Nicolai Schlenzig,
Denmark
Snippet from my handler:
sub handler
{
my $r = Apache2::Request->new( shift, POST_MAX => 524288 );
return 404 if($r->filename =~ /autohandler$/); # never allow access to
this directly!
return 404 if($r->filename =~ /dhandler$/); # same!
return 404 if($r->filename =~ /\.m$/); # reserve this mask for
components!
my $filesize = 0;
#eval {
# $filesize = $r->upload("file1")->size;
#};
#return 404 if( $filesize > 524288 );
my $status = $ah->handle_request($r);
return $status;
}
Snippet from my code:
if( my $upload = $r->upload("file1") ) {
my $filename = $upload->filename;
my $filedata = $upload->fh;
my $filesize = $upload->size;
my $filetype = $upload->type;
if( $filesize < 300000 ) {
my $content;
while( <$filedata> ) {
$content .= $_;
}
...
My HTML form:
<form name='files' enctype='multipart/form-data' action='/test/upload/'
method='post'>
<input type='file' name='file1' size='100'><br>
<!-- <input type='file' name='file2' size='100'><br> -->
<input type='submit'>
</form>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users