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?
const storageRef = firebase.storage().ref('files/myfile.txt'); await storageRef.put(file); await storageRef.updateMetadata({ customMetadata: { owner: 'user123' } });
Think about whether metadata updates affect the actual file data.
Updating metadata in Firebase Storage only changes the metadata fields. The file content stays the same and is not modified or duplicated.
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?
const storageRef = firebase.storage().ref('images/photo.jpg'); await storageRef.updateMetadata({ cacheControl: 'public, max-age=3600' });
Cache control headers define how long browsers keep files before checking for updates.
The value 'public, max-age=3600' tells browsers to cache the file publicly for 3600 seconds (1 hour). Other options either disable caching or set different durations.
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?
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;
}
}
}Check that only the customMetadata field is changed and the owner matches the authenticated user.
This rule ensures the update only changes customMetadata, the owner field remains consistent, and the user is authenticated as the owner.
You want to keep track of file versions in Firebase Storage using metadata. Which approach best supports versioning without duplicating files?
Think about how to track versions without creating multiple files.
Adding a version field in customMetadata allows tracking versions on the same file without duplicating storage. Renaming files duplicates storage, and cacheControl is unrelated.
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?
Consider whether metadata updates affect file access URLs.
Download URLs in Firebase Storage are tied to the file content and security token, not metadata. Updating metadata does not invalidate or change existing URLs.