[mod_python] Re: Mike's psp upload

Mike Looijmans nlv11281 at natlab.research.philips.com
Tue Jun 13 09:57:35 EDT 2006


The default behaviour of FieldStorage is to place the uploaded file in 
some temp location. By providing the callback, you can prevent the file 
being stored twice (once on temp, once on the final location). This 
allows uploading files of many gigabytes without consuming diskspace or 
memory.

Note that by doing:
    filedata = afile.file.read()
you read the entire file into system memory. If a user sends you a 1GB 
file, your server is likely to "die" there. Use one of the 
shutil.copyfile functions to copy the file to where you want, without 
(potentially) consuming megabytes of memory.


Mike Looijmans
Philips Natlab / Topic Automation


sandip more wrote:
> hello all,
>  I am also trying to implement file upload functionality with psp. I 
> didn't get the use of callback function.
> I am able to access the data of uploaded file with following code.
>  
> frm = util.FieldStorage(req)
> for afile in frm.getlist('UploadFile'):
>     filedata = afile.file.read()
>     #write filedata to some file in local directory with name 
> afile.filename.
>  
> can someone explain me..what is the need of this callback function? also 
> how it works?
>  
>  
> Thanks
> Sandip
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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