[mod_python] StringField instead of Field object on file upload form with method="get"

Bram bram-lists at phoenux.org
Mon May 9 11:59:51 EDT 2005

Ok. Just in case anyone else does something silly like I did here is 
what I learned. (redundant info for many, sorry ;) )

1. mod_python.publisher ingests form args into a FieldStorage( ) object 
stuffed into req.form on either form method, post or get.
2. If you use the form method post, formdata = 
mod_python.util.FieldStorage(req) will return empty.
3. If you use the form method get, formdata = 
mod_python.util.FieldStorage(req) will return with values, as will 
req.form. However, file upload form fields return as StringField objects 
that are the string version of the filename instead of the file object. Duh!
4. It is better to do it right and use post, and req.form

Bram Swenson.

Bram wrote:

> Duh,
> Sorry I found my own answer. req.form
> I apologize for this question.
> Thanks,
> Bram Swenson.
> Bram wrote:
>> Hello all,
>> I have a HTML form that look similar to this:
>> <form action="/py/upload_form" enctype="multipart/form-data" 
>> method="get">
>>      <input type="hidden" name="user_id" value="<%=user_id%>"></input>
>>    # PSP style template fills in user_id
>>      <li>Select your file :  <input type="file" 
>> name="filedata"></input> *</li>
>>      <li class="upload_button"><input type="submit" value="Upload" 
>> name="upload" id="upload"></input></li>
>> </form>
>> Then the upload_form.py file uses mod_python.util.FieldStorage to 
>> access the form values:
>> from mod_python import util
>> def handler(req):
>>    form_values = util.FieldStorage(req)
>> There are two things I am not understanding. One is that when the 
>> form method is set to post (as I think it should be) form_values is 
>> empty. But when I use "get" as I have shown above, the form_values 
>> object exists and has the correct data. This then leads to my second 
>> problems which is that when I use this method, 
>> form_values["filedata"] is StringField( ) object  instead of Field( ) 
>> object as excpected.
>> I mention both of the issues together as I suspect they are related. 
>> I suspect also that I a missing something simple, but I cannot put my 
>> finger on it.
>> Thanks in advance,
>> Bram Swenson.
>> _______________________________________________
>> 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