0
0
Firebasecloud~20 mins

File metadata in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase File Metadata Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Firebase Storage Metadata Update Behavior

You upload a file to Firebase Storage and then update its metadata to add a custom field. What happens to the file content after the metadata update?

Firebase
const storageRef = firebase.storage().ref('files/myfile.txt');
await storageRef.put(file);
await storageRef.updateMetadata({ customMetadata: { owner: 'user123' } });
AThe file content remains unchanged; only the metadata is updated.
BThe file content is overwritten with empty content during metadata update.
CThe file content is deleted and replaced with metadata only.
DThe file content is duplicated and stored twice after metadata update.
Attempts:
2 left
💡 Hint

Think about whether metadata updates affect the actual file data.

Configuration
intermediate
2:00remaining
Setting Cache Control Metadata for Firebase Storage Files

You want to set a cache control header on a file in Firebase Storage so browsers cache it for 1 hour. Which metadata configuration achieves this?

Firebase
const storageRef = firebase.storage().ref('images/photo.jpg');
await storageRef.updateMetadata({ cacheControl: 'public, max-age=3600' });
A{ cacheControl: 'no-cache' }
B{ cacheControl: 'public, max-age=3600' }
C{ cacheControl: 'private, max-age=3600' }
D{ cacheControl: 'max-age=86400' }
Attempts:
2 left
💡 Hint

Cache control headers define how long browsers keep files before checking for updates.

security
advanced
2:30remaining
Restricting Metadata Updates with Firebase Storage Security Rules

You want to allow users to update only the customMetadata.owner field of their files in Firebase Storage, but not other metadata fields. Which security rule snippet enforces this?

Firebase
service firebase.storage {
  match /b/{bucket}/o {
    match /files/{fileId} {
      allow update: if request.resource.metadata.customMetadata.owner == resource.metadata.customMetadata.owner &&
                    request.resource.metadata.keys().hasOnly(['customMetadata']) &&
                    request.auth.uid == request.resource.metadata.customMetadata.owner;
    }
  }
}
Aallow update: if request.resource.metadata.customMetadata.owner == resource.metadata.customMetadata.owner && request.auth.uid == request.resource.metadata.customMetadata.owner;
Ballow update: if request.auth.uid == resource.metadata.customMetadata.owner && request.resource.metadata.keys().hasOnly(['customMetadata']);
Callow update: if request.resource.metadata.customMetadata.owner == resource.metadata.customMetadata.owner && request.resource.metadata.keys().hasOnly(['customMetadata']) && request.auth.uid == request.resource.metadata.customMetadata.owner;
Dallow update: if request.resource.metadata.customMetadata.owner == request.auth.uid && request.resource.metadata.keys().hasOnly(['customMetadata']);
Attempts:
2 left
💡 Hint

Check that only the customMetadata field is changed and the owner matches the authenticated user.

Architecture
advanced
2:30remaining
Designing Metadata for Versioning Files in Firebase Storage

You want to keep track of file versions in Firebase Storage using metadata. Which approach best supports versioning without duplicating files?

AUse metadata <code>cacheControl</code> to indicate version numbers.
BRename files with version numbers in their names and keep metadata unchanged.
CStore version info only in Firestore, not in Storage metadata.
DAdd a <code>version</code> field in <code>customMetadata</code> and update it on each file overwrite.
Attempts:
2 left
💡 Hint

Think about how to track versions without creating multiple files.

🧠 Conceptual
expert
3:00remaining
Effect of Metadata on Firebase Storage Download URLs

You generate a download URL for a file in Firebase Storage. Later, you update the file's metadata (e.g., add customMetadata). What happens to the previously generated download URL?

AThe download URL remains valid and unchanged after metadata updates.
BThe download URL expires immediately when metadata is updated.
CThe download URL changes automatically to reflect new metadata.
DThe download URL becomes invalid and must be regenerated after metadata changes.
Attempts:
2 left
💡 Hint

Consider whether metadata updates affect file access URLs.