Temporary uploaded file API (TemporaryFile) is inadequate
|Reported by:||vomjom||Owned by:||Jacob|
|Cc:||vomjom@…, mike@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The temporary file is not properly deleted much of the time for me. There's already a known issue where if you kill/restart apache, the temporary files will stay around forever (at least until system reboot), but if you also fork a process and pass the files to it, they stick around. I don't understand why there's a TemporaryFile class inside of uploadhandler.py when it could just use tempfile.TemporaryFile (which unlinks the file immediately after creation, rather than at garbage collection).
The other issue with the uploadhandler.TemporaryFile class is that it's not iterable (it defines iter via its getattr, but that doesn't work), so it doesn't act like a real file object. This is an issue if you try to use some python libraries with the uploaded file, e.g. csv. This again would be fixed if tempfile.TemporaryFile was used.
Also, it's a bit strange that the UploadedFile API doesn't offer direct access to the file object. It seems to me that a very common use-case for upload handling is to process the file using python's standard library. Two examples I currently use in my program are zipfile and csv. Both require access to the underlying file object. It seems especially strange because the UploadedFile has a TemporaryFile object that it could return (although as I mentioned above, it is inadequate as a replacement for a file object). When handling and processing huge uploads, it doesn't seem right to force the user to chunk the UploadedFile to a new file (which much of the time will be temporary itself) to be able to open it in a standard python libs.
Change History (15)
comment:1 Changed 8 years ago by
|Owner:||changed from nobody to Jacob|
|Patch needs improvement:||unset|
|Status:||new → assigned|
|Triage Stage:||Unreviewed → Accepted|
comment:2 Changed 8 years ago by
|Summary:||Patch 2070 issues → Temporary uploaded file API (TemporaryFile) is inadequate|