Uploading images via cgi?

Paul Boddie paul at boddie.org.uk
Wed Aug 31 10:34:39 EDT 2005


Chris Dewin wrote:
> chunk = fileitem.file.read(100000), and fout.write (chunk) seem to be the
> key statements. Could  someone elaborate on these for me please? And why
> do they need to be in a while loop?

I imagine that the intention of reading only 100000 bytes at a time is
to limit the amount of memory used by the process. In an environment
where the process is kept around (not CGI, however) doing so might be
critical since it has been alleged that Python isn't particularly good
at freeing memory back to the operating system.

One way of limiting the total size of uploaded files might be to
examine the "Content-Length" header and to reject (ie. not process)
uploads involving files above a certain size.

Paul




More information about the Python-list mailing list