Create a Cloud Storage reference with Cloud Storage for Unity

Your files are stored in aCloud Storage bucket. Thefiles in this bucket are presented in a hierarchical structure, just like thefile system on your local hard disk, or the data in theFirebase Realtime Database.By creating a reference to a file, your app gains access to it. These referencescan then be used to upload or download data, get or update metadata or deletethe file. A reference can either point to a specific file or to a higher levelnode in the hierarchy.

If you've used theFirebase Realtime Database, these paths shouldseem very familiar to you. However, your file data is stored inCloud Storage,not in theRealtime Database.

Create a Reference

Create a reference to upload, download, or delete a file,or to get or update its metadata. A referencecan be thought of as a pointer to a file in the cloud. References arelightweight, so you can create as many as you need. They are also reusable formultiple operations.

References are created from theFirebase.Storage.FirebaseStorage service onyour Firebase app by calling theGetReferenceFromUrl() method and passing in aURL of the formgs://<your-cloud-storage-bucket>. You can find this URL intheStorage section of theFirebase console.

// Get a reference to the storage service, using the default Firebase AppFirebaseStoragestorage=FirebaseStorage.DefaultInstance;// Create a storage reference from our storage serviceStorageReferencestorageRef=storage.GetReferenceFromUrl("gs://<your-cloud-storage-bucket>");

You can create a reference to a location lower in the tree, for example'images/space.jpg', by using thechild method on an existing reference.

// Create a child reference// imagesRef now points to "images"StorageReferenceimagesRef=storageRef.Child("images");// Child references can also take paths delimited by '/' such as:// "images/space.jpg".StorageReferencespaceRef=imagesRef.Child("space.jpg");// spaceRef now points to "images/space.jpg"// imagesRef still points to "images"// This is equivalent to creating the full referencedStorageReferencespaceRefFull=storage.GetReferenceFromUrl("gs://<your-cloud-storage-bucket>/images/space.jpg");

Navigate with References

You can also use theParent andRoot methods to navigate up in our filehierarchy.Parent navigates up one level, whileRoot navigates all the wayto the top.

// Parent allows us to move to the parent of a reference// imagesRef now points to 'images'StorageReferenceimagesRef=spaceRef.Parent;// Root allows us to move all the way back to the top of our bucket// rootRef now points to the rootStorageReferencerootRef=spaceRef.Root;

Child,Parent, andRoot can be chained together multiple times, aseach returns a reference. The exception is theParent ofRoot, whichis an invalidStorageReference.

// References can be chained together multiple times// earthRef points to "images/earth.jpg"StorageReferenceearthRef=spaceRef.Parent.Child("earth.jpg");// nullRef is null since the parent of root is an invalid StorageReferenceStorageReferencenullRef=spaceRef.Root.Parent;

Reference Methods

You can inspect references to better understand the files they point to usingthePath,Name, andBucket properties. These properties get the file'sfull path, name, and bucket.

// Reference's path is: "images/space.jpg"// This is analogous to a file path on diskstringpath=spaceRef.Path;// Reference's name is the last segment of the full path: "space.jpg"// This is analogous to the file namestringname=spaceRef.Name;// Reference's bucket is the name of the storage bucket where files are storedstringbucket=spaceRef.Bucket;

Limitations on References

Reference paths and names can contain any sequence of valid Unicode characters,but certain restrictions are imposed including:

  1. Total length ofreference.Path must be between 1 and 1024 bytes when UTF-8encoded.
  2. No Carriage Return or Line Feed characters.
  3. Avoid using#,[,],*, or?, as these do not work well withother tools such as theFirebase Realtime Databaseorgsutil.

Full Example

FirebaseStoragestorage=FirebaseStorage.DefaultInstance;// Points to the root referenceStorageReferencestorageRef=storage.GetReferenceFromUrl("gs://<your-bucket-name>");// Points to "images"StorageReferenceimagesRef=storageRef.Child("images");// Points to "images/space.jpg"// Note that you can use variables to create child valuesstringfilename="space.jpg";StorageReferencespaceRef=imagesRef.Child(filename);// File path is "images/space.jpg"stringpath=spaceRef.Path;// File name is "space.jpg"stringname=spaceRef.Name;// Points to "images"StorageReferenceimagesRef=spaceRef.Parent;

Next Steps

Next, let's learn how toupload files toCloud 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.