// 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>");
// 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");
// 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;
// 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'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;
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;
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-08 (世界標準時間)。"],[],[],null,["\u003cbr /\u003e\n\nYour files are stored in a\n[Cloud Storage](//cloud.google.com/storage) bucket. The\nfiles in this bucket are presented in a hierarchical structure, just like the\nfile system on your local hard disk, or the data in the Firebase Realtime Database.\nBy creating a reference to a file, your app gains access to it. These references\ncan then be used to upload or download data, get or update metadata or delete\nthe file. A reference can either point to a specific file or to a higher level\nnode in the hierarchy.\n\nIf you've used the [Firebase Realtime Database](/docs/database), these paths should\nseem very familiar to you. However, your file data is stored in\nCloud Storage, **not** in the Realtime Database.\n\nCreate a Reference\n\nCreate a reference to upload, download, or delete a file,\nor to get or update its metadata. A reference\ncan be thought of as a pointer to a file in the cloud. References are\nlightweight, so you can create as many as you need. They are also reusable for\nmultiple operations.\n\nReferences are created from the `Firebase.Storage.FirebaseStorage` service on\nyour Firebase app by calling the `GetReferenceFromUrl()` method and passing in a\nURL of the form `gs://\u003cyour-cloud-storage-bucket\u003e`. You can find this URL in\nthe *Storage section* of the [Firebase console](//console.firebase.google.com/). \n\n```c#\n// Get a reference to the storage service, using the default Firebase App\nFirebaseStorage storage = FirebaseStorage.DefaultInstance;\n\n// Create a storage reference from our storage service\nStorageReference storageRef =\n storage.GetReferenceFromUrl(\"gs://\u003cyour-cloud-storage-bucket\u003e\");\n```\n\nYou can create a reference to a location lower in the tree, for example\n`'images/space.jpg'`, by using the `child` method on an existing reference. \n\n```c#\n// Create a child reference\n// imagesRef now points to \"images\"\nStorageReference imagesRef = storageRef.Child(\"images\");\n\n// Child references can also take paths delimited by '/' such as:\n// \"images/space.jpg\".\nStorageReference spaceRef = imagesRef.Child(\"space.jpg\");\n// spaceRef now points to \"images/space.jpg\"\n// imagesRef still points to \"images\"\n\n// This is equivalent to creating the full referenced\nStorageReference spaceRefFull = storage.GetReferenceFromUrl(\n \"gs://\u003cyour-cloud-storage-bucket\u003e/images/space.jpg\");\n```\n\nNavigate with References\n\nYou can also use the `Parent` and `Root` methods to navigate up in our file\nhierarchy. `Parent` navigates up one level, while `Root` navigates all the way\nto the top. \n\n```c#\n// Parent allows us to move to the parent of a reference\n// imagesRef now points to 'images'\nStorageReference imagesRef = spaceRef.Parent;\n\n// Root allows us to move all the way back to the top of our bucket\n// rootRef now points to the root\nStorageReference rootRef = spaceRef.Root;\n```\n\n`Child`, `Parent`, and `Root` can be chained together multiple times, as\neach returns a reference. The exception is the `Parent` of `Root`, which\nis an invalid `StorageReference`. \n\n```c#\n// References can be chained together multiple times\n// earthRef points to \"images/earth.jpg\"\nStorageReference earthRef =\n spaceRef.Parent.Child(\"earth.jpg\");\n\n// nullRef is null since the parent of root is an invalid StorageReference\nStorageReference nullRef = spaceRef.Root.Parent;\n```\n\nReference Methods\n\nYou can inspect references to better understand the files they point to using\nthe `Path`, `Name`, and `Bucket` properties. These properties get the file's\nfull path, name, and bucket. \n\n```c#\n// Reference's path is: \"images/space.jpg\"\n// This is analogous to a file path on disk\nstring path = spaceRef.Path;\n\n// Reference's name is the last segment of the full path: \"space.jpg\"\n// This is analogous to the file name\nstring name = spaceRef.Name;\n\n// Reference's bucket is the name of the storage bucket where files are stored\nstring bucket = spaceRef.Bucket;\n```\n\nLimitations on References\n\nReference paths and names can contain any sequence of valid Unicode characters,\nbut certain restrictions are imposed including:\n\n1. Total length of `reference.Path` must be between 1 and 1024 bytes when UTF-8 encoded.\n2. No Carriage Return or Line Feed characters.\n3. Avoid using `#`, `[`, `]`, `*`, or `?`, as these do not work well with other tools such as the [Firebase Realtime Database](/docs/database) or [gsutil](https://cloud.google.com/storage/docs/gsutil).\n\nFull Example \n\n```c#\nFirebaseStorage storage = FirebaseStorage.DefaultInstance;\n\n// Points to the root reference\nStorageReference storageRef =\n storage.GetReferenceFromUrl(\"gs://\u003cyour-bucket-name\u003e\");\n\n// Points to \"images\"\nStorageReference imagesRef = storageRef.Child(\"images\");\n\n// Points to \"images/space.jpg\"\n// Note that you can use variables to create child values\nstring filename = \"space.jpg\";\nStorageReference spaceRef = imagesRef.Child(filename);\n\n// File path is \"images/space.jpg\"\nstring path = spaceRef.Path;\n\n// File name is \"space.jpg\"\nstring name = spaceRef.Name;\n\n// Points to \"images\"\nStorageReference imagesRef = spaceRef.Parent;\n```\n\nNext Steps\n\nNext, let's learn how to\n[upload files](/docs/storage/unity/upload-files) to\nCloud Storage."]]