On Fri, 2008-09-26 at 12:52:49 -0500, Ian Bicking wrote: > Audrius Kažukauskas wrote: > > You can do this somewhere in the beginning of paste.request module: > > > > class MyFieldStorage(cgi.FieldStorage): > > def make_file(): ... # Your code here > > > > cgi.FieldStorage = MyFieldStorage > > > > It's a bit hacky, but it works (I tested it myself). > > > > BTW, maybe Paste author (it's Ian Bicking, right? :-) could come with > > more convenient way (public API calls?) to control this without the need > > of code modification in paste.request? > > That's possible, but looking at the source of tempfile it uses the > environmental variables $TMPDIR, $TEMP, and $TMP to figure out where to > put temporary files, and setting those values should be easy in > comparison to these other techniques. Patching cgi.FieldStorage would > allow for more fine-grained control (just where uploads go, instead of > all temp files), but I'm not sure how important that really is.
OK, my use case: Web app lets upload big files (let's say, up to 100 MiB) and keeps them for some time. Right now they go to /tmp and it could be changed with environmental variables, as you said. But the problem is that files created by tempfile.TemporaryFile can only be read from or written to (at least in POSIX or Cygwin systems). You can't *move* them, only copy from them. And the saddest part is, they disappear when closed. Hence you must write data to some other file. So information is copied twice: when uploading to the temporary file and after that to some permanent file. If web app is used more intensively or files are getting bigger, this is inefficient. If your files are small, you can calmly ignore what is said above. I'm not saying this is needed very often, but in some cases this information is very handy to know. It could at least be mentioned somewhere in documentation. -- Audrius Kažukauskas
pgpk11oK44YeS.pgp
Description: PGP signature
