0
0
Firebasecloud~10 mins

Upload progress monitoring in Firebase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Upload progress monitoring
Start Upload
Upload Begins
Listen to Progress Event
Calculate % Uploaded
Update Progress UI
Upload Complete?
NoContinue Upload
Yes
Upload Finished
This flow shows how an upload starts, progress events are listened to, progress percentage is calculated and UI updated until upload finishes.
Execution Sample
Firebase
const uploadTask = storageRef.put(file);
uploadTask.on('state_changed', snapshot => {
  const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
  console.log('Upload is ' + progress + '% done');
});
This code uploads a file and logs the upload progress percentage as it changes.
Process Table
StepEvent TriggeredbytesTransferredtotalBytesProgress %Action Taken
1Upload starts010000Upload begins, progress 0%
2state_changed200100020Log 'Upload is 20% done'
3state_changed500100050Log 'Upload is 50% done'
4state_changed800100080Log 'Upload is 80% done'
5state_changed10001000100Log 'Upload is 100% done', upload complete
💡 Upload completes when bytesTransferred equals totalBytes (1000), progress reaches 100%
Status Tracker
VariableStartAfter 1After 2After 3After 4Final
bytesTransferred020050080010001000
totalBytes100010001000100010001000
progress0205080100100
Key Moments - 2 Insights
Why does progress sometimes jump in big steps instead of smoothly increasing?
Progress updates depend on the 'state_changed' events from Firebase, which may fire irregularly as chunks upload. See execution_table rows 2-4 where progress jumps from 20% to 50% to 80%.
What happens if totalBytes is zero or unknown?
If totalBytes is zero, dividing by zero causes progress calculation issues. Firebase usually provides totalBytes, but if missing, progress can't be calculated properly. This is why totalBytes is tracked constant in variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the progress % at step 3?
A20%
B80%
C50%
D100%
💡 Hint
Check the 'Progress %' column in execution_table row 3.
At which step does the upload complete?
AStep 4
BStep 5
CStep 3
DStep 2
💡 Hint
Look for when bytesTransferred equals totalBytes in execution_table.
If bytesTransferred was 400 at step 2 instead of 200, what would progress % be?
A40%
B20%
C50%
D80%
💡 Hint
Calculate (bytesTransferred / totalBytes) * 100 using variable_tracker values.
Concept Snapshot
Upload progress monitoring in Firebase:
- Use uploadTask.on('state_changed') to listen for progress
- Calculate progress as (bytesTransferred / totalBytes) * 100
- Update UI or log progress inside the event handler
- Upload completes when bytesTransferred equals totalBytes
- Progress events may fire irregularly, showing jumps
Full Transcript
This visual execution trace shows how Firebase upload progress monitoring works. The upload starts and triggers 'state_changed' events. Each event provides bytesTransferred and totalBytes. Progress percentage is calculated by dividing bytesTransferred by totalBytes and multiplying by 100. The progress is logged or shown in UI. The upload finishes when bytesTransferred equals totalBytes. The execution table tracks each step's bytesTransferred, totalBytes, and progress percent. Variable tracker shows how these values change over time. Key moments clarify why progress jumps and the importance of totalBytes. The quiz tests understanding of progress values at steps and calculations.