Process Flow - File metadata
Upload File
Store File in Storage
Attach Metadata
Retrieve Metadata
Use Metadata for Info or Control
This flow shows how a file is uploaded, stored with metadata, and later retrieved to access its metadata.
const fileRef = storageRef.child('images/photo.jpg'); await fileRef.put(file); await fileRef.updateMetadata({ contentType: 'image/jpeg', customMetadata: { author: 'Alice' } }); const meta = await fileRef.getMetadata(); console.log(meta.contentType, meta.customMetadata.author);
| Step | Action | Result | Metadata State |
|---|---|---|---|
| 1 | Create reference to 'images/photo.jpg' | Reference created | {} |
| 2 | Upload file to reference | File stored | {} |
| 3 | Update metadata with contentType and customMetadata | Metadata updated | {"contentType":"image/jpeg","customMetadata":{"author":"Alice"}} |
| 4 | Retrieve metadata from file | Metadata retrieved | {"contentType":"image/jpeg","customMetadata":{"author":"Alice"}} |
| 5 | Log contentType and author | Output: image/jpeg Alice | {"contentType":"image/jpeg","customMetadata":{"author":"Alice"}} |
| 6 | End | Process complete | {"contentType":"image/jpeg","customMetadata":{"author":"Alice"}} |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|---|
| fileRef | undefined | Reference to 'images/photo.jpg' | Reference to 'images/photo.jpg' | Reference to 'images/photo.jpg' | Reference to 'images/photo.jpg' | Reference to 'images/photo.jpg' |
| meta | undefined | undefined | undefined | undefined | {"contentType":"image/jpeg","customMetadata":{"author":"Alice"}} | {"contentType":"image/jpeg","customMetadata":{"author":"Alice"}} |
File metadata in Firebase Storage: - Upload file to storage reference - Use updateMetadata() to set contentType and customMetadata - Retrieve metadata with getMetadata() - Metadata is separate from file content - Metadata must be explicitly set and can be updated anytime