When uploading a file to the Django server, using HTML form and POST method, it is not always clear what is the used upload handler and if the file is saved to the temporary folder or just kept in the memory.
Here is one way to detect if the file is stored to the temporary folder or not.
uploaded_file = request.FILES['file']
if isinstance(uploaded_file, TemporaryUploadedFile):
# file has exceeded the value FILE_UPLOAD_MAX_MEMORY_SIZE
# and it has been saved to the temporary folder
# closing the file will delete the file
return "file too large"
# file is instance of InMemoryUploadedFile
# handle file
Other comparison function that can be used is:
if hasattr(uploaded_file, 'temporary_file_path'):