[mod_python] finding length of user file before uploading

Graham Dumpleton grahamd at dscpl.com.au
Fri Apr 14 23:01:04 EDT 2006

On 15/04/2006, at 12:54 PM, Graham Dumpleton wrote:

> On 15/04/2006, at 12:36 PM, greg wrote:
>> I want a script (PSP preferred, custom handler if need be) that can
>> cancel an upload if the file is too large, or is taking too long.
>> The list archives have a few hacks for custom uploads using:
>> 	util.FieldStorage(req, file_callback=FileFactory)
>> However, this parameter is not in the official docs, and several
>> previous posters noticed the behaviour breaking between versions.
>> My system is Debian, Apache2, mod_python 3.1.3-3.
>> When I try the file_callback trick, I get:
>>   File "/var/www/upload.psp", line 40, in ?
>>     frm = util.FieldStorage(req, file_callback=make_file)
>> TypeError: __init__() got an unexpected keyword argument  
>> 'file_callback'
>> I presume that undocumented feature has become extinct in recent  
>> versions.
>> And, even if it had worked, it still doesn't relay the size of the
>> file until the transfer is eating time and memory.
>> I would like to avoid making a custom handler that gets the data  
>> directly from the client--it seems like I would re-invent the  
>> wheel. A slower wheel.
>> What is the best way to aquire the filesize before the upload starts?
> The file_callback and field_callback parameters are new features in
> unreleased 3.2.9 and 3.3.X. That is why you can find them. See
> documentation at:

Whoops. The file_callback feature is in 3.2.8 source code, but web site
documentation doesn't mention it. The thing I got confused about as only
being in 3.2.9/3.3.X was some more recent performance improvements
to the same code.

Anyway, upgrade from your older 3.1.3 to 3.2.8 and you will have access
to the feature. You will though need to refer to documentation out of
the source code repository.


More information about the Mod_python mailing list