A. The event name should be 'state_changed', not 'state_change'
B. The callback function is missing a return statement
C. You must use uploadTask.addListener instead of on
D. The progress calculation formula is incorrect
Solution
Step 1: Check event name spelling
The correct event name is 'state_changed', not 'state_change'.
Step 2: Understand impact of wrong event name
Using wrong event name means callback never triggers, so no logs appear.
Final Answer:
The event name should be 'state_changed', not 'state_change' -> Option A
Quick Check:
Event name must be exact 'state_changed' [OK]
Hint: Check event spelling: 'state_changed' not 'state_change' [OK]
Common Mistakes:
Misspelling event names
Expecting logs without callback firing
Confusing method names like addListener vs on
5. You want to display upload progress as a percentage and also show a message when upload completes. Which code snippet correctly implements this using Firebase Storage's state_changed event?
hard
A. uploadTask.on('progress', snapshot => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(`Upload is ${progress}% done`);
});
B. uploadTask.on('state_changed', snapshot => {
console.log('Upload complete!');
});