0
0
Firebasecloud~20 mins

Uploading files in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Storage Upload Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What happens when you upload a file with the same name to Firebase Storage?

You upload a file named image.png to Firebase Storage. Then you upload another file with the same name image.png to the same location. What is the result?

AThe new file overwrites the existing file silently.
BFirebase Storage creates a new file with a unique name to avoid overwriting.
CThe upload fails with an error about duplicate file name.
DBoth files are stored and Firebase Storage merges their contents.
Attempts:
2 left
💡 Hint

Think about how cloud storage usually handles files with the same path.

security
intermediate
2:00remaining
Which Firebase Storage security rule allows only authenticated users to upload files?

Choose the Firebase Storage security rule snippet that restricts file uploads to authenticated users only.

Firebase
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow write: if <condition>;
    }
  }
}
Arequest.auth == null
Bresource.size < 1048576
Crequest.time < timestamp.date(2025, 1, 1)
Drequest.auth != null
Attempts:
2 left
💡 Hint

Authenticated users have a non-null request.auth object.

Configuration
advanced
2:00remaining
What is the correct way to get a download URL after uploading a file in Firebase Storage using JavaScript?

After uploading a file to Firebase Storage, you want to get its public download URL. Which code snippet correctly does this?

Firebase
import { getStorage, ref, uploadBytes, getDownloadURL } from 'firebase/storage';

const storage = getStorage();
const storageRef = ref(storage, 'files/myFile.txt');

// Assume file is a File object from input
uploadBytes(storageRef, file).then((snapshot) => {
  // What goes here?
});
AgetDownloadURL(snapshot.ref).then(url => console.log(url));
BstorageRef.getDownloadURL().then(url => console.log(url));
Csnapshot.downloadURL.then(url => console.log(url));
DuploadBytes.getDownloadURL(storageRef).then(url => console.log(url));
Attempts:
2 left
💡 Hint

Look at the Firebase Storage API for getting download URLs after upload.

Architecture
advanced
2:00remaining
Which Firebase Storage architecture best supports large file uploads with resume capability?

You want to allow users to upload large files that can resume if interrupted. Which Firebase Storage upload method supports this?

ASplit the file manually and upload parts with <code>uploadBytes()</code>.
BUse <code>uploadBytes()</code> method with retry logic in your code.
CUse <code>uploadBytesResumable()</code> method with progress listeners.
DUse Firebase Realtime Database to store file chunks.
Attempts:
2 left
💡 Hint

Firebase Storage has a built-in method for resumable uploads.

Best Practice
expert
3:00remaining
What is the best practice to secure Firebase Storage uploads to prevent unauthorized overwrites?

You want to prevent users from overwriting files uploaded by others in Firebase Storage. Which security rule approach achieves this?

AAllow write only if the file size is less than 1MB.
BAllow write only if the file does not exist yet: <code>resource == null</code> and user is authenticated.
CAllow write only if the user is authenticated, ignoring file existence.
DAllow write only during business hours.
Attempts:
2 left
💡 Hint

Think about how to prevent overwriting existing files by checking their existence.