Not getting all keys in FieldStorage (Multipart form data)

vivek kumar gupt_vive at hotmail.com
Wed Jun 4 11:26:34 CEST 2003


Hi all,

  Here is one problem I am facing while loading multipart form data. Like I 
have code for creating form for loading images..

print '<form name="bookimage" 
action="%s/admin/additem.py?bookid=%s&image=yes" method="post" 
enctype="multipart/form-data">' %(environ.ENV_PATH,itemid)
print '<font size=4>Book Cover Image : <input type="file" name="book_image" 
size=50><br><br><input type="submit" value="Load Image">'
print '</form>'

But when I try to retrive the bookid key from FieldStorage then it raises a 
Key error :-(. The code where I am trying to get this...

         form=cgi.FieldStorage()
         if form.has_key("book_image"):
                loadfile=form["book_image"]
                id=form["bookid"].value
                from os.path import splitext
                ext=os.path.splitext(loadfile[1])[1][1:]
                ......

I have tried to print the contents of the FieldStorage Object also like..

            if form.has_key("book_image"):
                print 'content-type:text/html\n'
                print form
                return

But here also it shows only the book_image key and data.

Is this because I am using multipart form data type or there is some error 
with the code??
If it is because of multipart form data then how can I pass an ID or some 
other value with the image??

TIA and Kind Regards
Vivek Kumar

_________________________________________________________________
Watch Hallmark. Enjoy cool movies 
http://server1.msn.co.in/sp03/hallmark/index.asp Win hot prizes!






More information about the Python-list mailing list