Bird
Raised Fist0
Firebasecloud~20 mins

File metadata in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of file metadata in Firebase Storage?
easy
A. To store extra information about files like type and custom tags
B. To store the actual file content
C. To manage user authentication
D. To create database records

Solution

  1. Step 1: Understand what metadata means

    Metadata is data about data, so it holds extra info about files, not the files themselves.
  2. Step 2: Identify the role of metadata in Firebase Storage

    Firebase Storage uses metadata to store info like file type and custom tags to help manage files better.
  3. Final Answer:

    To store extra information about files like type and custom tags -> Option A
  4. Quick Check:

    File metadata = extra info about files [OK]
Hint: Metadata holds info about files, not the files themselves [OK]
Common Mistakes:
  • Confusing metadata with file content
  • Thinking metadata manages users
  • Assuming metadata creates database records
2. Which of the following is the correct way to set custom metadata for a file in Firebase Storage using JavaScript?
easy
A. storageRef.updateMetadata({ customMetadata: { owner: 'user1' } })
B. storageRef.setMetadata({ owner: 'user1' })
C. storageRef.metadata = { owner: 'user1' }
D. storageRef.uploadMetadata({ customMetadata: { owner: 'user1' } })

Solution

  1. Step 1: Recall Firebase Storage method for updating metadata

    The correct method to update metadata is updateMetadata(), not setMetadata or uploadMetadata.
  2. Step 2: Check the structure for custom metadata

    Custom metadata must be inside a customMetadata object within the metadata parameter.
  3. Final Answer:

    storageRef.updateMetadata({ customMetadata: { owner: 'user1' } }) -> Option A
  4. Quick Check:

    Use updateMetadata() with customMetadata object [OK]
Hint: Use updateMetadata() with customMetadata key [OK]
Common Mistakes:
  • Using setMetadata() which does not exist
  • Assigning metadata directly to storageRef
  • Using uploadMetadata() which is invalid
3. Given the following code snippet, what will be logged to the console?
const metadata = await storageRef.getMetadata();
console.log(metadata.contentType);
medium
A. The file's download URL
B. The file size in bytes
C. The MIME type of the file, e.g., 'image/png'
D. An error because getMetadata() returns undefined

Solution

  1. Step 1: Understand what getMetadata() returns

    getMetadata() returns an object with file metadata including contentType, size, and more.
  2. Step 2: Identify what metadata.contentType holds

    contentType holds the MIME type of the file, such as 'image/png' or 'application/pdf'.
  3. Final Answer:

    The MIME type of the file, e.g., 'image/png' -> Option C
  4. Quick Check:

    metadata.contentType = MIME type [OK]
Hint: contentType in metadata shows file type [OK]
Common Mistakes:
  • Thinking contentType is file size
  • Expecting download URL from metadata
  • Assuming getMetadata() returns undefined
4. You try to update file metadata with this code but get an error:
await storageRef.updateMetadata({ owner: 'user1' });
What is the likely cause?
medium
A. updateMetadata() cannot update metadata
B. storageRef is not defined
C. owner is not a valid metadata field
D. Missing the customMetadata wrapper around owner

Solution

  1. Step 1: Check the structure required for custom metadata

    Custom metadata must be inside a customMetadata object, not directly as a field.
  2. Step 2: Identify the error cause

    Passing { owner: 'user1' } directly causes an error because owner is not a top-level metadata field.
  3. Final Answer:

    Missing the customMetadata wrapper around owner -> Option D
  4. Quick Check:

    Custom metadata needs customMetadata key [OK]
Hint: Wrap custom fields inside customMetadata object [OK]
Common Mistakes:
  • Passing custom fields directly without customMetadata
  • Thinking updateMetadata() can't update metadata
  • Ignoring storageRef definition errors
5. You want to tag files uploaded by users with their user ID and file category. Which is the best way to store this info in Firebase Storage metadata?
hard
A. Add user ID and category as top-level metadata fields
B. Use customMetadata with keys 'userId' and 'category' inside updateMetadata()
C. Save user ID and category in Firestore only, not in metadata
D. Store user ID and category in the file name

Solution

  1. Step 1: Understand how to store extra info in Firebase Storage

    Firebase Storage supports customMetadata to store extra info like tags.
  2. Step 2: Evaluate options for tagging files

    Using customMetadata keys 'userId' and 'category' inside updateMetadata() is the best practice for tagging files.
  3. Step 3: Why other options are less ideal

    File names can get messy, Firestore is separate, and top-level metadata fields do not support custom keys.
  4. Final Answer:

    Use customMetadata with keys 'userId' and 'category' inside updateMetadata() -> Option B
  5. Quick Check:

    Tag files using customMetadata keys [OK]
Hint: Use customMetadata keys for tagging files [OK]
Common Mistakes:
  • Putting tags in file names instead of metadata
  • Relying only on Firestore for file tags
  • Trying to add custom fields as top-level metadata
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard