ImperialCollegeLondon / django-drf-filepond

A Django app providing a server implemention for the Filepond file upload library
BSD 3-Clause "New" or "Revised" License
103 stars 39 forks source link

Chunked uploads fail when upload file size is an exact multiple of chunk size #72

Closed jcohen02 closed 2 years ago

jcohen02 commented 2 years ago

When handling a chunked upload, django-drf-filepond receives the size of the file upload that it expects and creates a temporary database object to track the upload of the file chunks.

Once all file chunks have been uploaded, the final file is created and saved and the TemporaryUploadChunked object is deleted.

However, when the filepond client is processing a chunked upload where the file is an exact multiple of the chunk size, it results in a final chunk of 0 size as a result of the calculation on this line in src/js/app/utils/processFileChunked.js.

With django-drf-filepond, the final PATCH request with an empty payload results in an attempt to handle a patch for a file that has been processed and saved because all data has been received. The TemporaryUploadChunked object associated with the request no longer exists so it fails.

The sample filepond-server-php server implementation doesn't have a problem with this since it seems to accept any PATCH request with any 'patch' ID and no content and return a 204 code.

The best way to resolve this with django-drf-filepond is probably going to be to check if the incoming patch request has an offset that is equal to the file length and a content length of 0. If so we simply accept the request and do nothing. As a further check, we could also verify that there is a completed temporary upload corresponding to the ID.