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

I'm having a problem with a file upload CGI script. It seems no matter how high I set $CGI::POST_MAX (using CGI.pm), I can never upload more than 1 mb to the server. The error code return by the server is "413 Request Entity Too Large". Doesn't seem to matter if the file is binary or text and everything smaller than 1 MB uploads fine.

Could there be a server setting to adjust or is there a problem with my code?

$CGI::POST_MAX=1024*100000; my $q = new CGI; my $myFile = $q->upload('file'); binmode($myFile); if (!$myFile && cgi_error()) { print $q->header(-status=>cgi_error()); print $q->p("Error"); exit 0; } my $dir = "c:\\inetpub\\scripts\\perl\\uploads"; open (MYFILE,">$dir\\test_upload.txt") || die $!; binmode(MYFILE); while (<$myFile>) {print MYFILE $_; } close (MYFILE);
Server is NT4 SP6a
IIS4
Active State Perl 5.6.1

Thanks for the help!

Replies are listed 'Best First'.
Re: File upload limited to 1 M B
by Hero Zzyzzx (Curate) on Oct 18, 2002 at 13:43 UTC

    This looks like a server setting- I do relatively large uploads (some larger than 10 meg) with CGI.pm regularly and it works flawlessly on a mod_perl'd apache/linux box.

    Plus, the status code is probably coming from IIS, unless there's a part of your code that returns a 413 (doubtful, and you'd know it.) Can't help you much about where to tweak the IIS settings, though, I'm pretty much a *nix guy.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

      I haven't had any trouble either doing this with apache/linux. ...but I can't seem to find anything on the server that controls upload size.

      Thanks for taking a look.

Re: File upload limited to 1 M B
by strider corinth (Friar) on Oct 18, 2002 at 13:49 UTC
    The sites I looked at containing scripts in other languages for IIS4 show that the limit can be set higher than 1MB by the scripts themselves. Since that isn't working for you (but it does seem to work sometimes on IIS4), it's almost certainly a limit set on the server, but probably not one that's hard coded.
    --

    Love justice; desire mercy.
Re: File upload limited to 1 M B
by Anonymous Monk on Oct 18, 2002 at 15:02 UTC
    Think outside the box, grasshopper:
    Make absolutely sure you don't have a proxy server in between.
    Squid defaulted to a 1MB POST limit, IIRC.
      Alright then, I guess you found the problem first. I should have checked before posting the follow-up. :)

      I feel a bit silly. Guess I'll be sliding back down to -1. Thank You.

Re: File upload limited to 1 M B
by jiggs (Acolyte) on Oct 18, 2002 at 15:08 UTC
    Alright, I found the problem.

    There is a transparent proxy (squid) between the users and the web server and that seems the issue. Everything works fine when it's bypassed. We'll look for a config setting there. Thanks again.

Re: File upload limited to 1 M B
by Anonymous Monk on Oct 18, 2002 at 17:31 UTC
    Check the LWP modules. There is a default file buffer size setting that can be changed/increased to allow files greater than 1.0Mb in size. TTD