Challenge - 5 Problems
Cloud Storage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
How does React Native handle file upload progress with cloud storage?
You want to show a progress bar while uploading a file to cloud storage in React Native. Which code snippet correctly updates the progress state during upload?
React Native
import {useState} from 'react'; import {uploadBytesResumable, ref} from 'firebase/storage'; const uploadFile = (file, storage) => { const [progress, setProgress] = useState(0); const storageRef = ref(storage, 'files/' + file.name); const uploadTask = uploadBytesResumable(storageRef, file); uploadTask.on('state_changed', snapshot => { const percent = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; setProgress(percent); }); return progress; };
Attempts:
2 left
💡 Hint
The event name for upload progress updates is 'state_changed'.
✗ Incorrect
The 'state_changed' event provides snapshot data including bytesTransferred and totalBytes, which you use to calculate upload progress percentage.
🧠 Conceptual
intermediate1:30remaining
What is the purpose of Firebase Storage security rules?
Why do we use security rules in Firebase Cloud Storage for a React Native app?
Attempts:
2 left
💡 Hint
Think about protecting user data and access permissions.
✗ Incorrect
Security rules define who can upload, download, or delete files, protecting your storage from unauthorized access.
❓ lifecycle
advanced1:30remaining
What happens if you try to download a non-existent file from Firebase Storage?
In React Native, if you call getDownloadURL() on a reference to a file that does not exist in Firebase Storage, what will happen?
Attempts:
2 left
💡 Hint
Check how Firebase Storage handles missing files.
✗ Incorrect
Firebase Storage rejects the promise with a specific error code when the file is not found.
📝 Syntax
advanced2:00remaining
Which code correctly deletes a file from Firebase Storage in React Native?
You want to delete a file named 'image.png' from Firebase Storage. Which code snippet correctly performs this action?
React Native
import {ref, deleteObject} from 'firebase/storage'; const deleteFile = async (storage) => { const fileRef = ref(storage, 'images/image.png'); await deleteObject(fileRef); };
Attempts:
2 left
💡 Hint
Remember to pass the storage instance to ref and await the async deleteObject call.
✗ Incorrect
You must create a reference with storage and path, then await deleteObject with that reference.
🔧 Debug
expert2:30remaining
Why does this React Native Firebase Storage upload code never update progress?
Consider this code snippet for uploading a file. The progress state never updates. What is the cause?
React Native
const uploadFile = (file, storage) => {
const [progress, setProgress] = useState(0);
const storageRef = ref(storage, 'files/' + file.name);
const uploadTask = uploadBytesResumable(storageRef, file);
uploadTask.on('state_changed', snapshot => {
const percent = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
setProgress(percent);
});
return progress;
};Attempts:
2 left
💡 Hint
Think about React hooks and component state lifecycle.
✗ Incorrect
useState inside a function that is called repeatedly resets state each time, so progress never updates visually.