Consider this Firebase Storage upload snippet that tracks progress:
const uploadTask = storageRef.put(file);
uploadTask.on('state_changed', snapshot => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(`Upload is ${progress}% done`);
});What will be logged if 500 bytes are transferred out of 2000 bytes total?
const snapshot = { bytesTransferred: 500, totalBytes: 2000 };
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(`Upload is ${progress}% done`);Calculate the percentage: (transferred / total) * 100.
500 bytes out of 2000 bytes is 25% progress.
A developer uses uploadTask.on('state_changed', ...) to track upload progress, but the callback never runs. What is the most likely cause?
Check if the file to upload is valid.
If the file is undefined or null, the upload never starts, so progress events don't fire.
Given this Firebase Storage security rule snippet, which option correctly restricts uploads to authenticated users and allows progress monitoring?
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read: if true;
allow write: if ...;
}
}
}Authenticated users have a non-null request.auth.
Allowing write only if request.auth != null restricts uploads to signed-in users, enabling secure progress monitoring.
Order these steps correctly for uploading a file with progress monitoring and completion handling in Firebase Storage:
First create reference, then start upload, then listen for progress, then handle completion.
You must create the reference before uploading. The upload starts with put(), then you attach listeners to track progress and completion.
For large file uploads, which method best improves user experience by providing accurate progress feedback and allowing upload pause/resume?
Firebase Storage uploadTask supports pause and resume natively.
Using uploadTask's built-in progress events and pause/resume methods provides smooth user feedback and control during large uploads.