According to the docs:
However, if an uploaded file is too large, Django will write the uploaded file to a temporary file stored in your system’s temporary directory. On a Unix-like platform this means you can expect Django to generate a file called something like
/tmp/tmpzfp6I6.upload
. If an upload is large enough, you can watch this file grow in size as Django streams the data onto disk.
So I have uploaded several times the same big file to a view and got this:
vic@vic /tmp $ ls -l tmp*.upload
-rw------- 1 vic vic2 3436110 мая 14 18:31 tmpKdZrQl.upload
-rw------- 1 vic vic2 3436110 мая 14 18:31 tmpqLyBsy.upload
When these files are deleted from the temp directory?
I want to avoid bloating the temp directory.
To write these tempfiles, Django uses the tempfile module in python. You can see django's code in django/core/files/temp.py
.
A django temp file is a tempfile.NamedTemporaryFile
. Here's a link to the code. The default settings in that constructor (plus code that's in django) calls for the file to be deleted when it is closed.
So watch out for filehandle links; if they're not getting deleted, it is likely that your code is leaking the filehandle, and never closing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With