[mod_python] File upload limits

Graham Dumpleton grahamd at dscpl.com.au
Wed Jun 15 23:46:58 EDT 2005

Kai Hendry wrote ..
> I am writing a Web application which requires the user to upload a file.
> It seems sensible to me to limit how large the file upload can be. After
> searching around it seems that I need to modify Apache's content-length
> attribute and that mod_python is what I should look at.
> It would be nice if the FieldStorage class:
> http://www.modpython.org/live/current/doc-html/pyapi-util-fstor-fld.html
> Had an input limit, because I can't see one.
> Does anyone have an example of this type of input checking I am after?

Why do you feel you need to "modify Apache's content-length attribute"?

I can understand you wanting to reject a request based on input
content length being larger than a certain amount, but not what
would be gained from modifying the content length.

As long as you aren't using mod_python.publisher, you could insert
into your handler before you use the FieldStorage class a check of
the req.headers_in["content-length"] field to see if the combined total
of all form parameters in the POST containing the upload was
greater than some amount and reject it on that basis. Not sure if
the req.clength is the same thing as the "content-length" header or

Without duplicating what FieldStorage does, can't see how you would
be able to reject it based on just the file upload part of a multipart
POST request being larger than a certain size.


More information about the Mod_python mailing list