Mod_python

Graham Dumpleton grahamd at dscpl.com.au
Wed Dec 27 17:38:19 EST 2006


Maxim Sloyko wrote:
> Lad wrote:
> > In my web application I use Apache and mod_python.
> > I allow users to upload huge files( via HTTP FORM , using POST method)
> > I would like to store the file directly on a hard disk and not to
> > upload the WHOLE huge file into  server's memory first.
> > Can anyone suggest a solution?
>
> The only solution you need is Apache and mod_python :)
> I mean,  Apache won't load a huge POST request into its memory no
> matter what. All file uploads will be stored in temporary files. Under
> mod_python (provided you use FieldStorage) you'll need to deal only
> with 'file' objects.

Note though that the default behaviour of FieldStorage is to store
files in whatever directory the 'tempfile' module uses. This may not
always be acceptable, especially with very large files, as the user may
want to have the files actually reside elsewhere in some special
directory and having to make a copy of the file, if a different file
system, may in itself cause issues.

Thus, provided you are using a recent version of mod_python, you still
may have to customise how files are handled using the FieldStorage file
callbacks to have the file stored in the desired location from the
outside.

The other alternative to FieldStorage is to write a custom
Apache/mod_python input filter to process uploads. An example of this
is Tramline (http://www.infrae.com/products/tramline).

Graham




More information about the Python-list mailing list