Use file metadata with Cloud Storage for Unity 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,SizeBytes, andContentType (often referred to as MIME type) in addition to someless common ones likeContentDisposition andCreationTimeMillis. Thismetadata can be retrieved from aCloud Storage reference using theGetMetadataAsync method.
// Create reference to the file whose metadata we want to retrieveStorageReferenceforestRef=storageRef.Child("images/forest.jpg");// Get metadata propertiesforestRef.GetMetadataAsync().ContinueWithOnMainThread(task=>{if(!task.IsFaulted &&!task.IsCanceled){StorageMetadatameta=task.Result;// do stuff with meta}});
Update File Metadata
You can update file metadata at any time after the file upload completes byusing theUpdateMetadataAsync method which takes aMetadataChange object.Refer to thefull list for more information on whatproperties can be updated. Only the properties specified in the metadata areupdated, all others are left unmodified.
// Create reference to the file whose metadata we want to changeStorageReferenceforestRef=storageRef.Child("images/forest.jpg");// Create file metadata to updatevarnewMetadata=newMetadataChange();newMetadata.CacheControl="public,max-age=300";newMetadata.ContentType="image/jpeg";// Update metadata propertiesforestRef.UpdateMetadataAsync(newMetadata).ContinueWithOnMainThread(task=>{if(!task.IsFaulted &&!task.IsCanceled){// access the updated meta dataStorageMetadatameta=task.Result;}});
You can delete writable metadata properties by passing the empty string:
// Create file metadata to updatevarnewMetadata=newMetadataChange();newMetadata.ContentType="";// Update metadata propertiesforestRef.UpdateMetadataAsync(newMetadata).ContinueWithOnMainThread(task=>{if(!task.IsFaulted &&!task.IsCanceled){StorageMetadatameta=task.Result;// meta.ContentType should be an empty string now}});
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 aDictionary<string, string>.
varnewMetadata=newMetadataChange{CustomMetadata=newDictionary<string,string>{{"location","Yosemite, CA, USA"},{"activity","Hiking"}}};// UpdateMetadataAsync
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 | Modifyable in MetadataChange |
|---|---|---|
Bucket | string | NO |
Generation | string | NO |
MetadataGeneration | string | NO |
Path | string | NO |
Name | string | NO |
SizeBytes | long | NO |
CreationTimeMillis | long | NO |
UpdatedTimeMillis | long | NO |
CacheControl | string | YES |
ContentDisposition | string | YES |
ContentEncoding | string | YES |
ContentLanguage | string | YES |
ContentType | string | YES |
DownloadUrl | Uri | NO |
DownloadUrls | IList<Uri> | NO |
CustomMetadataKeys | IEnumerable<string> | YES |
Next Steps
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.