defnull/bottle — Issue #288: Allow for zero-copy file uploads.
Author: jtolds
Created: 2012-02-19 23:45:46+00:00
State: open

Right now, Bottle directly calls cgi.FieldStorage to parse incoming data.

cgi.FieldStorage has a 'make_file' method defined with the following comment:

"""Overridable: return a readable & writable file.

The file will be used as follows:
- data is written to it
- seek(0)
- data is read from it

The 'binary' argument is unused -- the file is always opened
in binary mode.

This version opens a temporary file for reading and writing,
and immediately deletes (unlinks) it. The trick (on Unix!) is
that the file can still be used, but it can't be opened by
another process, and it will automatically be deleted when it
is closed or when the current process terminates.

If you want a more permanent file, you derive a class which
overrides this method. If you want a visible temporary file
that is nevertheless automatically deleted when the script
terminates, try defining a __del__ method in a derived class
which unlinks the temporary files you have created.

"""

It would be nice if Bottle allowed more easy access to providing your own FieldStorage class implementation, or perhaps specifically allowed for optionally providing a make_file implementation.

My use case is that I would like to have Bottle upload file data directly to its final storage location, instead of being uploaded to a tempfile and then being copied again to its final destination.