[mod_python] finding length of user file before uploading

Mike Looijmans nlv11281 at natlab.research.philips.com
Tue Apr 18 01:41:32 EDT 2006

If you check the content-length header BEFORE you do anything with a 
form, PSP won't use the fieldstorage yet, and you'll be in time to 
report an error.

The correct behaviour for these cases is to use the '100 continue' 
system, but the client has to request that with an expect-continue 
header. I'm not sure how you can trigger a browser to wait for a 
'continue' request. Or is apache already handling this under water?

Note that you'll have to forcibly close the connection if you are not 
using the 100 continue response, because the client will keep dumping 
data your way...

Mike Looijmans
Philips Natlab / Topic Automation

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?
> Thanks,
> Greg
> _______________________________________________
> 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