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

Add support for handling uploads with an empty final chunk - fixes #72 #73

Closed jcohen02 closed 2 years ago

jcohen02 commented 2 years ago

As described in #72, an upload that has a size that is an exact multiple of the upload chunk size set on the filepond client configuration results in the upload of an empty final chunk.

Previously this was not handled correctly since as soon as django-drf-filepond detects that the amount of data received for an upload is equal to the data size specified in the upload headers, it goes ahead and processes the uploaded chunks, converting them to the full file and storing this as a TemporaryUpload object. The database record created to track the chunks being uploaded is then removed. When the final chunk upload comes in with no data, it doesn't match a TemporaryUploadChunked object so the PATCH request fails and the upload on the client side then fails too.

This has been addressed by checking if a PATCH request has no data. If that's the case, the headers are checked to verify that the request relates to an upload where all data has already been transferred and if that's the case, the request is accepted. The upload then completes successfully on the client side.