Is there a way to treat a file in request.FILES
same as a disk file? I want to do something like this:
with open(file_in_request, 'rb') as file:
#read data from that file
Only, I don't want to have to save it to disk first. I will be encrypting that file and save the encrypted file to disk instead.
TLDR: by modifying FILE_UPLOAD_MAX_MEMORY_SIZE
Django variable to a large enough value to keep files in memory.
By default, Django stores file with a size of 2.5 MB in memory and file larger than that size are stored in a temporary disk location.
The reason for this behavior is that keeping large files in memory can overwhelm your system. Read it here in docs.
In your case, if you know the max file size and are sure that it won't be large enough to fill up your computer memory you can modify the threshold value FILE_UPLOAD_MAX_MEMORY_SIZE
variable to a large enough value to make sure all the files are in memory.
From the docs:
The maximum size (in bytes) that an upload will be before it gets streamed to the file system. See Managing files for details
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