When uploading a file for a field such as this one:
file = FileField(upload_to='/path/')
Django uses either an InMemoryUploadedFile
or a TemporaryUploadedFile
. The latter is stored on the disk and its file name can be accessed with the temporary_file_path
property. The storage choice depends on the file size.
How can I override this behaviour and always upload as a TemporaryUploadedFile
for this model field?
The reason I am asking this is because I need to write a validator that uses an external library that can only take file paths as input, no data streams.
By default the upload handlers are:
[
'django.core.files.uploadhandler.MemoryFileUploadHandler',
'django.core.files.uploadhandler.TemporaryFileUploadHandler',
]
And files smaller than 2.5MB are handled with MemoryFileUploadHandler
.
So just say in your settings:
FILE_UPLOAD_HANDLERS = ['django.core.files.uploadhandler.TemporaryFileUploadHandler',]
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