In this episode, we dive into how to let users cancel an ongoing upload using the upchunk
package. We'll start by adding a simple "Cancel" button to our interface. You'll see how to wire up this button so that when clicked, it triggers a function to abort the actual upload request. This involves interacting directly with the upload state and calling the abort
method, effectively killing the XHR request that's sending the file.
We also discuss why it's useful to bring back throttling here—so you can react in time when you hit the cancel button and see the effect in your UI and network tab. Once cancelled, it's important to reset your application's state: clear the uploader, set progress back to zero, and make sure the user can start a new upload if they want to.
By the end, you'll see the entire process, from clicking "cancel" to the network request being stopped, the UI clearing out, and getting everything ready for the next upload. Next up: we'll tackle pausing uploads, which works a lot like what we just built here.