Use file metadata with Cloud Storage on Apple platforms Stay organized with collections Save and categorize content based on your preferences.
After uploading a file toCloud Storage reference, you can also getand update the file metadata, for example to update the content type. Filescan also store custom key/value pairs with additional file metadata.
Note: By default, aCloud Storage for Firebase bucket requiresFirebase Authenticationto perform any action on the bucket's data or files. You can change yourFirebase Security Rules forCloud Storage toallow unauthenticated access for specific situations.However, for most situations, we strongly recommendrestricting access and setting up robust security rules(especially for production apps). Note that if you useGoogleApp Engine and have a defaultCloud Storage bucket with a nameformat of*.appspot.comGet File Metadata
File metadata contains common properties such asname,size, andcontentType (often referred to as MIME type) in addition to some lesscommon ones likecontentDisposition andtimeCreated. This metadata can beretrieved from aCloud Storage reference usingthemetadataWithCompletion: method.
Swift
// Create reference to the file whose metadata we want to retrieveletforestRef=storageRef.child("images/forest.jpg")// Get metadata propertiesdo{letmetadata=tryawaitforestRef.getMetadata()}catch{// ...}
Objective-C
// Create reference to the file whose metadata we want to retrieveFIRStorageReference*forestRef=[storageRefchild:@"images/forest.jpg"];// Get metadata properties[forestRefmetadataWithCompletion:^(FIRStorageMetadata*metadata,NSError*error){if(error!=nil){// Uh-oh, an error occurred!}else{// Metadata now contains the metadata for 'images/forest.jpg'}}];
Update File Metadata
You can update file metadata at any time after the file upload completes byusing theupdateMetadata:withCompletion: method. Refer to thefull list for more information on what propertiescan be updated. Only the properties specified in the metadata are updated,all others are left unmodified.
Swift
// Create reference to the file whose metadata we want to changeletforestRef=storageRef.child("images/forest.jpg")// Create file metadata to updateletnewMetadata=StorageMetadata()newMetadata.cacheControl="public,max-age=300"newMetadata.contentType="image/jpeg"// Update metadata propertiesdo{letupdatedMetadata=tryawaitforestRef.updateMetadata(newMetadata)}catch{// ...}
Objective-C
// Create reference to the file whose metadata we want to changeFIRStorageReference*forestRef=[storageRefchild:@"images/forest.jpg"];// Create file metadata to updateFIRStorageMetadata*newMetadata=[[FIRStorageMetadataalloc]init];newMetadata.cacheControl=@"public,max-age=300";newMetadata.contentType=@"image/jpeg";// Update metadata properties[forestRefupdateMetadata:newMetadatacompletion:^(FIRStorageMetadata*metadata,NSError*error){if(error!=nil){// Uh-oh, an error occurred!}else{// Updated metadata for 'images/forest.jpg' is returned}}];
You can delete writable metadata properties by setting them tonil:
Objective-C
FIRStorageMetadata*newMetadata=[[FIRStorageMetadataalloc]init];newMetadata.contentType=nil;// Delete the metadata property[forestRefupdateMetadata:newMetadatacompletion:^(FIRStorageMetadata*metadata,NSError*error){if(error!=nil){// Uh-oh, an error occurred!}else{// metadata.contentType should be nil}}];
Swift
letnewMetadata=StorageMetadata()newMetadata.contentType=nildo{// Delete the metadata propertyletupdatedMetadata=tryawaitforestRef.updateMetadata(newMetadata)}catch{// ...}
Handle Errors
There are a number of reasons why errors may occur on getting or updatingmetadata, including the file not existing, or the user not having permissionto access the desired file. More information on errors can be found in theHandle Errorssection of the docs.
Custom Metadata
You can specify custom metadata as anNSDictionary containingNSStringproperties.
Swift
letmetadata=["customMetadata":["location":"Yosemite, CA, USA","activity":"Hiking"]]
Objective-C
NSDictionary*metadata=@{@"customMetadata":@{@"location":@"Yosemite, CA, USA",@"activity":@"Hiking"}};
You can store app-specific data for each file in custom metadata, but we highlyrecommend using a database (such as theFirebase Realtime Database) to store and synchronize this type ofdata.
File Metadata Properties
A full list of metadata properties on a file is available below:
| Property | Type | Writable |
|---|---|---|
bucket | String | No |
generation | String | No |
metageneration | String | No |
fullPath | String | No |
name | String | No |
size | Int64 | No |
timeCreated | Date | No |
updated | Date | No |
md5Hash | String | Yes |
cacheControl | String | Yes |
contentDisposition | String | Yes |
contentEncoding | String | Yes |
contentLanguage | String | Yes |
contentType | String | Yes |
customMetadata | [String: String] | Yes |
md5Hash property on upload doesn't affect theupload, as hash verification is not yet implemented.Uploading, downloading, and updating files is important, but so is being ableto remove them. Let's learn how todelete filesfromCloud Storage.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.