Does uploadTask.cancel()
work only with large files? I am trying to upload a file of which it works but also the file upload should be cancellable of which in my case it only works with large files small files upload even though I have cancelled the file upload.
What is probably happening is that the small files are uploaded very fast and by the time you call cancel()
, they have already been uploaded. You didn't provide any code, but I assume you're executing uploadTask.cancel()
in the click of a button. So I recommend that you check if the task is completed before cancelling it. And if it is, delete the small file. You can use this code for that:
if (!uploadTask.isComplete()) {
//Upload is not complete yet, let's cancel
uploadTask.cancel();
} else {
//Upload is complete, but user wanted to cancel. Let's delete the file
uploadTask.snapshot.ref.delete();
// storageRef.delete(); // will delete all your files
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With