Graham Dumpleton
graham.dumpleton at gmail.com
Wed Aug 22 18:24:54 EDT 2007
On 23/08/07, Jonathan Frankel <wikiterra at gmail.com> wrote: > 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 > functions? As I said previously, req.form is only automatically created when using publisher. Ie., when you have PythonHandler set to mod_python.publisher. It is a feature of that high level handler that it does this. If you are implementing your own low level handler it will not be done, nor will you have the feature of form fields being able to be passed as distinct arguments to your handler. Research the mod_python documentation to satisfy yourself what the distinction is between basic low level handler and high level publisher handler. Then you may not be so confused. > 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 > confusing. Since those pages are part of a complete set of tutorial pages someone has written for using mod_python, maybe you should go back to the start and read them all. Note that I found these pages by doing a Google search. I haven't actually looked at them in a very long time and am not familiar with them, but the contents on the right side of the page suggests it covers what you want, although the examples may be specific to publisher in many cases. > 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. I'm not familiar with the example. As I said I pointed it out as it was one of the first pages that appear in Google search. Other may have the time to help you understand it, I am a bit busy at the moment. Sorry. Graham > Thanks again, > Jonathan > > 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 > > > > > >
|