File Uploads
Upload flow
End users can upload files through the File Upload component when they fill out forms.
The following events happen during that process:
The user adds a file to the component:
A
POSTrequest is made to/api/v1/formio/fileuploadwith the content of the file.If configured, the file is scanned for viruses (more details here). In case a virus is found, the file is not saved and the user receives an error alerting them that a virus was found in the file.
An instance of the
openforms.submissions.models.TemporaryFileUploadmodel is created.The endpoint returns the url of the file
/api/v1/submissions/files/<uuid>, the file name and size. This information is added to the Formio submission step data.The UUID of the
openforms.submissions.models.TemporaryFileUploadis added to the user session.The content of the file is saved to the disk. The file is placed in the private media directory (configured through the
PRIVATE_MEDIA_ROOTsetting), within thetemporary-uploadsfolder.
The user saves the form step:
An instance of
openforms.submissions.models.SubmissionFileAttachmentis created (with a relation to theopenforms.submissions.models.TemporaryFileUpload).The file gets copied to the
submission-uploadsfolder (which is also in the private media directory).
The user completes the submission:
The UUID of the
openforms.submissions.models.TemporaryFileUploadis removed from the session.The task
cleanup_temporary_files_fordeletes allopenforms.submissions.models.TemporaryFileUploadassociated with the submission that has been completed.
Note
When instances of openforms.submissions.models.TemporaryFileUpload and
openforms.submissions.models.SubmissionFileAttachment are deleted, the associated
files are removed from the file system (thanks to the openforms.utils.files.DeleteFileFieldFilesMixin mixin).
Periodical clean up
There are Celery beat tasks that periodically clean up files:
The task
cleanup_unclaimed_temporary_filescleans up anyopenforms.submissions.models.TemporaryFileUploadwhich is not related to aopenforms.submissions.models.SubmissionFileAttachment. This task runs once a day.The task
delete_submissionsdeletes any successful/incomplete/errored submission that are older than a configured amount of time. This deletes the associatedopenforms.submissions.models.SubmissionFileAttachment. This task runs once a day.The task
make_sensitive_data_anonymousclears any sensitive data from a submission. It also deletes anyopenforms.submissions.models.SubmissionFileAttachmentrelated to the submission being cleaned. This task runs once a day.