Description:
Using the PersistedTemporaryFileUploadHandler upload handler, Django will write the uploaded file to a temporary file stored in your system's temporary directory, as the TemporaryFileUploadHandler already do. However, the file this time will not be suppressed after your first read, and will persist until you delete it.
PersistedTemporaryFileUploadHandler class inherit from the TemporaryFileUploadHandler class. No big changes, only to set the delete args of the NamedTemporaryFile to False
Use cases:
- One use case that I personally faced is having many threads
reading from the same uploaded file. When one of the threads reads the
file content, the file is automatically deleted, and so became
unavailable for the other threads.
- Another use case was find in a stack overflow question, where a user was looking for a way to control the life time of the uploaded file.
N.B:
Even thought it may be easy to forbid the temporary file from being
deleted, I think it's a necessary feature or class to have withing the
framework as it's a behavior that I would naturally consider available
in such a great framework.