Maki Script
BUFFERSIZE = 1024 * 512 # for file uploads
def saveFile(self, name, targetFilename):
"""If "name" corresponds to an uploaded file, then open a
file on the server specified by the fully-qualified filename
"targetFilename" and write the file.
Return 1 if file "name" existed and was saved successfully.
Return 0 if no file existed for "name".
An exception may be raised if file I/O fails.
"""
if(not self.get(name)): return 0
upfile = self.getFile(name)
if(upfile):
targetfile = open(targetFilename, "w")
try:
while(1):
buffer = upfile.read(BUFFERSIZE)
if(buffer): targetfile.write(buffer)
else: break
finally:
targetfile.close()
upfile.close()
return 1
else:
return 0