Skip to content
Advertisement

Firebase Storage Web: uploadTask.cancel() is not working reactjs

I want to cancel the upload task at the click of a button. But it is not working(it returns false and I can view the file in the firebase storage console) below is the full code of the component

Upload.js

JavaScript

Here is what’s happening in the console after I click on cancel(after clicking upload and setting a file(img, 3.15mb))

the image link on imgur

if I just do

JavaScript

it returns true and the upload actually gets cancelled

Advertisement

Answer

Turns out it was a scope-related issue… I had to make the uploadTask globally available by making it a react state to implement it in my code and I called the uploadTask.cancel() in my button callback…I used useEffect to monitor my uploadTask and I am doing setLoading(false) at the button callback instead of the error callback

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement