Not getting all keys in FieldStorage (Multipart form data)
vivek kumar
gupt_vive at hotmail.com
Wed Jun 4 08:26:51 EDT 2003
>From: "Graeme Matthew" <gsmatthew at ozemail.com.au>
>To: "vivek kumar" <gupt_vive at hotmail.com>
>Subject: Re: Not getting all keys in FieldStorage (Multipart form data)
>Date: Wed, 4 Jun 2003 22:06:53 +1000
>
>Keeping that in mind try this:
>
>import shutil
>BUFFER = 1024
>
>file = form['book_image'].file #this will be a
>file
>handle in FieldStorage
>destination = open('C;/help.jpeg','wb') #This will be destinate
>file (might need to create it first)
>shutil.copyfileobj(file,destination,1024) #Copy file to file
I tried this also. But it works with the text files but it does not save
binary files successfully :-(. Here is the code I used as you suggested
form=cgi.FieldStorage()
if form.has_key("aimsfile"):
loadfile=form["aimsfile"].file
from shutil import copyfileobj
from os.path import splitext
from shutil import copyfileobj
ext=os.path.splitext(form["aimsfile"].filename)[1][1:]
try:
savefile=open("1.%s" %ext,"wb")
copyfileobj(loadfile,savefile,1024)
savefile.close()
except Exception,e:
print "Not saved..",str(e)
>
>Hope this helps ?
TIA and Kind Regards
Vivek Kumar
_________________________________________________________________
HCL Beanstalk PCs. You could win one.
http://server1.msn.co.in/sp03/hclbeanstalktour/index.asp Interested?
More information about the Python-list
mailing list