إنشاء مرجع في Cloud Storage باستخدام Cloud Storage من أجل Unity
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يتم تخزين ملفاتك في حزمة Cloud Storage. يتم عرض الملفات في هذه الحزمة في بنية هرمية، تمامًا مثل نظام الملفات على القرص الثابت المحلي أو البيانات في Firebase Realtime Database.
من خلال إنشاء مرجع لملف، يمكن لتطبيقك الوصول إليه. ويمكن استخدام هذه المراجع لتحميل البيانات أو تنزيلها أو الحصول على البيانات الوصفية أو تعديلها أو حذف الملف. يمكن أن يشير المرجع إلى ملف معيّن أو إلى عقدة ذات مستوى أعلى في التدرّج الهرمي.
إذا سبق لك استخدام Firebase Realtime Database، من المفترض أن تكون هذه المسارات مألوفة جدًا بالنسبة إليك. ومع ذلك، يتم تخزين بيانات ملفاتك في Cloud Storage، وليس في Realtime Database.
إنشاء مرجع
إنشاء مرجع لتحميل ملف أو تنزيله أو حذفه،
أو للحصول على البيانات الوصفية الخاصة به أو تعديلها يمكن اعتبار المرجع
مؤشرًا إلى ملف في السحابة الإلكترونية. المراجع بسيطة، لذا يمكنك إنشاء العدد الذي تحتاجه منها. ويمكن أيضًا إعادة استخدامها في عمليات متعددة.
يتم إنشاء المراجع من خدمة Firebase.Storage.FirebaseStorage في تطبيقك على Firebase من خلال استدعاء طريقة GetReferenceFromUrl() وتمرير عنوان URL بالصيغة gs://<your-cloud-storage-bucket>. يمكنك العثور على عنوان URL هذا في قسم "مساحة التخزين" ضمن وحدة تحكّم Firebase.
// 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>");
يمكنك إنشاء مرجع إلى موقع أدنى في الشجرة، مثلاً
'images/space.jpg'، باستخدام طريقة child على مرجع حالي.
// 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 وRoot للتنقّل للأعلى في التسلسل الهرمي للملفات. يؤدي الضغط على Parent إلى الانتقال إلى مستوى واحد للأعلى، بينما يؤدي الضغط على Root إلى الانتقال إلى أعلى مستوى.
// 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 وRoot معًا عدة مرات، لأنّ كلّ منها يعرض مرجعًا. الاستثناء هو Parent من Root، وهو StorageReference غير صالح.
// 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;
طُرق الإشارة إلى المراجع
يمكنك فحص المراجع لفهم الملفات التي تشير إليها بشكل أفضل باستخدام الخصائص Path وName و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;
القيود المفروضة على المراجع
يمكن أن تحتوي مسارات المراجع وأسماؤها على أي تسلسل من أحرف Unicode الصالحة،
ولكن يتم فرض قيود معيّنة، بما في ذلك:
يجب أن يتراوح الطول الإجمالي لـ reference.Path بين 1 و1024 بايت عند استخدام الترميز UTF-8.
يجب عدم استخدام أحرف الرجوع إلى أول السطر أو نهاية السطر.
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;
الخطوات التالية
بعد ذلك، سنتعرّف على كيفية
تحميل الملفات إلى
Cloud Storage.
تاريخ التعديل الأخير: 2025-08-08 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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."]]