[mod_python] How to do file uploads

Jonathan Frankel wikiterra at gmail.com
Wed Aug 22 13:45:01 EDT 2007

Ahh, okay. Am I correct in thinking, then, that calling "req.form"
instantiates a FieldStorage object? Namely, making "form," the
FieldStorage object, a new attribute of req? Or does "req.form"
already exist as soon as mod_python hands req off to one of my own

Also, what is the preferred, or better way, to access form data? Is it
always more "efficient" or "secure" to use the FieldStorage object, or
is it just as good to use something like--

def getData(req, field1, field2):

The documentation uses the latter in its examples of reading form
data, and then goes on to say that FieldStorage can be used to access
form data...but doesn't actually show any examples of this. And this
link you sent me--which is very helpful, thank you--doesn't mention
passing form data to functions as arguments. So...I find this kind of

Finally, about the file upload. The "Big File Upload" link you sent
says at the top that it buffers the input so that it doesn't "memory
starve the server if the file is a bit bigger." Does this mean when
the buffer function is called, it only gets the specified amount of
data in each chunk from the client in discrete steps? I ask this
because I was under the impression that when you make the statement,
"req.form['file'].file" you've already gotten all of the data from the
client onto the server.

Thanks again,

On 8/21/07, Graham Dumpleton <graham.dumpleton at gmail.com> wrote:
> See:
>   http://webpython.codepoint.net/mod_python_publisher_file_upload
>   http://webpython.codepoint.net/mod_python_publisher_big_file_upload
> req.form only exists if you are using publisher. If not using
> publisher, add to start of handler the code:
>   req.form = util.FieldStorage(req)
> to create it.
> Graham
> On 22/08/07, Jonathan Frankel <wikiterra at gmail.com> wrote:
> > Hello, I'm just using mod_python for the first time, and I'm trying to
> > figure out how to do file uploads. However, I'm completely confused
> > with this. From the documentation it seems to indicate that the best
> > way to do it is to use the FieldStorage class...except I can't see how
> > the examples provided have anything to do with file uploads.
> >
> > When I search around I find very little, though the popular method
> > seems to be to use req.form['file'].file to return a file object.
> > Except I can't find where the documentation says anything about a
> > "form" attribute in req. Furthermore, I see people saying that it's
> > best to pass the data from the client through an input filter, which
> > sounds good and I kind of sort of get it, but don't know how to
> > implement it and can't find any examples.
> >
> > Can anyone provide me with an example that allows a client to upload a
> > file, and limits it to a certain size? I really think that this sort
> > of thing should be provided as an example. If I get this working, I'll
> > gladly donate my code to put up on the examples page.
> >
> > Thanks in advance,
> > Jonathan
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
> >

More information about the Mod_python mailing list