Use file metadata with Cloud Storage for C++ 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, andcontent_type (often referred to as MIME type) in addition to some less commonones likecontent_disposition andtime_created. This metadata can beretrieved from aCloud Storage reference using theGetMetadatamethod.
// Create reference to the file whose metadata we want to retrieveStorageReferenceforest_ref=storage_ref.Child("images/forest.jpg");// Get metadata propertiesFuturefuture=forest_ref.GetMetadata();// Wait for Future to complete...if(future.Error()!=firebase::storage::kErrorNone){// Uh-oh, an error occurred!}else{// We can now retrieve the metadata for 'images/forest.jpg'Metadata*metadata=future.Result();}
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 changefirebase::storage::StorageReferenceforest_ref=storage_ref.child("images/forest.jpg");// Create file metadata to updateMetadatanew_metadata;newMetadata.set_cache_control("public,max-age=300");newMetadata.set_content_type("image/jpeg");// Update metadata propertiesFuturefuture=forest_ref.UpdateMetadata(new_metadata);// Wait for Future to complete...if(future.Error()!=firebase::storage::kErrorNone){// Uh-oh, an error occurred!}else{// We can now retrieve the updated metadata for 'images/forest.jpg'Metadata*metadata=future.Result();}
You can delete writable metadata properties by passing the empty string:
// Create file metadata with property to deleteStorageMetadatanew_metadata;new_metadata.set_content_type("");// Delete the metadata propertyFuturefuture=forest_ref.UpdateMetadata(new_metadata);// Wait for Future to complete...if(future.Error()!=0){// Uh-oh, an error occurred!}else{// metadata.content_type() should be an empty stringMetadata*metadata=future.Result();}
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 anstd::map containingstd::stringproperties.
std::map<std::string,std::string>*custom_metadata=metadata.custom_metadata();custom_metadata->insert(std::make_pair("location","Yosemite, CA, USA");custom_metadata->insert(std::make_pair("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 | const char* | NO |
generation | const char* | NO |
metageneration | const char* | NO |
full_path | const char* | NO |
name | const char* | NO |
size | int64_t | NO |
time_created | int64_t | NO |
updated | int64_t | NO |
cache_control | const char* | YES |
content_disposition | const char* | YES |
content_encoding | const char* | YES |
content_language | const char* | YES |
content_type | const char* | YES |
download_urls | std::vector<std::string> | NO |
custom_metadata | std::map<std::string, std::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.