Document purpose of UploadedFile model
sebhaase opened this issue · 6 comments
I'm trying to understand the steps happening while uploading, creating temp files and finally moving the tempfile to its final place.
At last I noticed that the model instance of UploadedFile
disappears after the form is submitted.
Do I understand this correct?
I'm missing the information like created-DateTime or original_filename.
Please document that this information would have to be saved separately in the custom model (like Example
in the testproject).
Maybe - if this is correct - it would even be advisable to rename the model from UploadedFile
to something like UploadingFile
. This would also alleviate the confusion currently found in models.py where UploadedFile
is a Model
while UploadedFileWithId
is derived from django.core.files.uploadedfile.UploadedFile
which is a django.core.files.base.File
which is a django.core.files.utils.FileProxyMixin
.
It's true, the UploadedFile
record is used temporarily and is removed after the form is submitted. I will update the documentation.
The name is indeed a bit problematic. The name UploadingFile
is also not completely correct, because that suggests that the file is not completely uploaded yet.
Another thought: maybe the UploadedFile
model is not necessary anymore. It was introduced in the first version, but later versions use the cache to store the tus-upload. Perhaps the cache can replace the model.
By the way, would it be possible to just rename / move the uploaded file from temp_uploads
to the final location? Currently it appears to require double the file size on the server temporarily, right?
I will see if that is possible.
I changed the model name to TemporaryUploadedFile
.
I have looked at the optimization mentioned above: 'is it possible to move the uploaded file?'. I think it's better not do this. The problem is that TemporaryUploadedFile
uses the Django file storage api, which doesn't support moving files. The file storage api makes it possible to use external storage like S3, which complicates this even more. Also see #313 for why the custom storage option was added.
Also see https://docs.djangoproject.com/en/3.1/ref/files/storage/
Update: it might be possible to optimize this after all. See pr #401
I added documentation about TemporaryUploadedFile