How to handle response of chunk uploading in Dropzone.js?

The popular js media uploading library dropzone.js is quite simple to integrate. It’s document widely had all the information to add it to any project within minutes.

Yasmin Bano , 04 January, 2021

In our recent project, we’ve used the chunking process of dropzone which is useful in big size files uploading. In chunk uploading, you can configure how much size each chunk should upload to the server.

All goes well as long as chunks are being successfully uploaded. The entire process will not notify if there is any error in between the chunks. The worst part is that the chunks will continue uploading till the last chunk of the file occurs.

In this blog, I am going to share how to handle the response of each chunk.

  • First, you need to clone the dropzone.js within your project.
  • In dropzone.js, under the `_finishedUploading` key if response is not successful then Add this code in the else condition.
  • Basically for each chunk response if there is any error then we will stop the process and throw the respective error.
  • After doing these changes, use the customized dropzone.js from your project instead of native one.
  • Now go back to the part where you’ve integrated the dropzone, listen to @error event.
  • On listening to the event you can handle the error.
  • That’s it and you’re good to go.
  • Happy Coding!
blog comments powered by Disqus