Use file metadata with Cloud Storage on Flutter

After uploading a file to Cloud Storage reference, you can also getand update the file metadata, for example to view or update the content type.Files can 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.com, you may need to considerhow your security rules impact access toApp Engine files.

Get 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 a Cloud Storage reference usingthegetMetadata() method.

// Create reference to the file whose metadata we want to retrievefinalforestRef=storageRef.child("images/forest.jpg");// Get metadata propertiesfinalmetadata=awaitforestRef.getMetadata();// 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() 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.

// Create reference to the file whose metadata we want to changefinalforestRef=storageRef.child("images/forest.jpg");// Create file metadata to updatefinalnewMetadata=SettableMetadata(cacheControl:"public,max-age=300",contentType:"image/jpeg",);// Update metadata propertiesfinalmetadata=awaitforestRef.updateMetadata(newMetadata);// Updated metadata for 'images/forest.jpg' is returned

You can delete writable metadata properties by passingnull:

// Delete the cacheControl propertyfinalnewMetadata=SettableMetadata(cacheControl:null);finalmetadata=awaitforestRef.updateMetadata(newMetadata);

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 Errors section of the docs.

Custom Metadata

You can specify custom metadata using thecustomMetadata parameter of theSettableMetadata constructor:

// Create reference to the file whose metadata we want to changefinalforestRef=storageRef.child("images/forest.jpg");// Create file metadata to updatefinalnewCustomMetadata=SettableMetadata(customMetadata:{"location":"Yosemite, CA, USA","activity":"Hiking",},);// Update metadata propertiesfinalmetadata=awaitforestRef.updateMetadata(newCustomMetadata);// Updated metadata for 'images/forest.jpg' is returned

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:

PropertyTypeSettable?
bucketStringNo
generationStringNo
metagenerationStringNo
metadataGenerationStringNo
fullPathStringNo
nameStringNo
sizeintNo
timeCreatedDateTimeNo
updatedDateTimeNo
md5HashStringNo
cacheControlStringYes
contentDispositionStringYes
contentEncodingStringYes
contentLanguageStringYes
contentTypeStringYes
customMetadataMap<String, String>Yes

Uploading, downloading, and updating files is important, but so is being ableto remove them. Let's learn how todelete filesfrom Cloud 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-03 UTC.