استخدام البيانات الوصفية للملفات مع Cloud Storage for Unity
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
بعد تحميل ملف إلى مرجع Cloud Storage، يمكنك أيضًا الحصول على البيانات الوصفية للملف وتعديلها، مثلاً لتعديل نوع المحتوى. يمكن للملفات أيضًا تخزين أزواج المفاتيح والقيم المخصّصة مع بيانات وصفية إضافية للملفات.
الحصول على البيانات الوصفية للملف
تحتوي البيانات الوصفية للملف على سمات شائعة، مثل Name وSizeBytes وContentType (يُشار إليها غالبًا باسم نوع MIME)، بالإضافة إلى بعض السمات الأقل شيوعًا، مثل ContentDisposition وCreationTimeMillis. يمكن استرداد هذه البيانات الوصفية من مرجع Cloud Storage باستخدام طريقة GetMetadataAsync.
// Create reference to the file whose metadata we want to retrieveStorageReferenceforestRef=storageRef.Child("images/forest.jpg");// Get metadata propertiesforestRef.GetMetadataAsync().ContinueWithOnMainThread(task=>{if(!task.IsFaulted && !task.IsCanceled){StorageMetadatameta=task.Result;// do stuff with meta}});
تعديل البيانات الوصفية للملف
يمكنك تعديل البيانات الوصفية للملف في أي وقت بعد اكتمال تحميله باستخدام طريقة UpdateMetadataAsync التي تتلقّى عنصر MetadataChange.
راجِع القائمة الكاملة لمزيد من المعلومات حول الخصائص التي يمكن تعديلها. يتم تعديل السمات المحدّدة في البيانات الوصفية فقط، بينما تبقى جميع السمات الأخرى بدون تعديل.
// Create reference to the file whose metadata we want to changeStorageReferenceforestRef=storageRef.Child("images/forest.jpg");// Create file metadata to updatevarnewMetadata=newMetadataChange();newMetadata.CacheControl="public,max-age=300";newMetadata.ContentType="image/jpeg";// Update metadata propertiesforestRef.UpdateMetadataAsync(newMetadata).ContinueWithOnMainThread(task=>{if(!task.IsFaulted && !task.IsCanceled){// access the updated meta dataStorageMetadatameta=task.Result;}});
يمكنك حذف خصائص البيانات الوصفية القابلة للكتابة عن طريق تمرير السلسلة الفارغة:
// Create file metadata to updatevarnewMetadata=newMetadataChange();newMetadata.ContentType="";// Update metadata propertiesforestRef.UpdateMetadataAsync(newMetadata).ContinueWithOnMainThread(task=>{if(!task.IsFaulted && !task.IsCanceled){StorageMetadatameta=task.Result;// meta.ContentType should be an empty string now}});
معالجة الأخطاء
هناك عدد من الأسباب التي قد تؤدي إلى حدوث أخطاء عند الحصول على البيانات الوصفية أو تعديلها، بما في ذلك عدم توفّر الملف أو عدم حصول المستخدم على إذن بالوصول إلى الملف المطلوب. يمكنك الاطّلاع على مزيد من المعلومات حول الأخطاء في قسم
التعامل مع الأخطاء
في المستندات.
البيانات الوصفية المخصّصة
يمكنك تحديد بيانات وصفية مخصّصة على أنّها Dictionary<string, string>.
varnewMetadata=newMetadataChange{CustomMetadata=newDictionary<string,string>{{"location","Yosemite, CA, USA"},{"activity","Hiking"}}};// UpdateMetadataAsync
يمكنك تخزين بيانات خاصة بالتطبيق لكل ملف في بيانات وصفية مخصّصة، ولكن ننصحك بشدة باستخدام قاعدة بيانات (مثل Firebase Realtime Database) لتخزين هذا النوع من البيانات ومزامنته.
خصائص البيانات الوصفية للملف
في ما يلي قائمة كاملة بخصائص البيانات الوصفية في ملف:
الموقع
النوع
قابلة للتعديل في MetadataChange
Bucket
string
لا
Generation
string
لا
MetadataGeneration
string
لا
Path
string
لا
Name
string
لا
SizeBytes
long
لا
CreationTimeMillis
long
لا
UpdatedTimeMillis
long
لا
CacheControl
string
نعم
ContentDisposition
string
نعم
ContentEncoding
string
نعم
ContentLanguage
string
نعم
ContentType
string
نعم
DownloadUrl
Uri
لا
DownloadUrls
IList<Uri>
لا
CustomMetadataKeys
IEnumerable<string>
نعم
الخطوات التالية
إنّ تحميل الملفات وتنزيلها وتعديلها مهم، ولكن من المهم أيضًا أن تتمكّن من إزالتها. لنتعرّف على كيفية
حذف الملفات
من 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\nAfter uploading a file to Cloud Storage reference, you can also get\nand update the file metadata, for example to update the content type. Files\ncan also store custom key/value pairs with additional file metadata.\n| **Note:** By default, a Cloud Storage for Firebase bucket requires Firebase Authentication to perform any action on the bucket's data or files. You can change your Firebase Security Rules for Cloud Storage to [allow unauthenticated access for specific situations](/docs/storage/security/rules-conditions#public). However, for most situations, we strongly recommend [restricting access and setting up robust security rules](/docs/storage/security/get-started) (especially for production apps). Note that if you use Google App Engine and have a default Cloud Storage bucket with a name format of `*.appspot.com`, you may need to consider [how your security rules impact access to App Engine files](/docs/storage/gcp-integration#security-rules-and-app-engine-files).\n\nGet File Metadata\n\nFile metadata contains common properties such as `Name`, `SizeBytes`, and\n`ContentType` (often referred to as MIME type) in addition to some\nless common ones like `ContentDisposition` and `CreationTimeMillis`. This\nmetadata can be retrieved from a Cloud Storage reference using the\n`GetMetadataAsync` method. \n\n```c#\n// Create reference to the file whose metadata we want to retrieve\nStorageReference forestRef =\n storageRef.Child(\"images/forest.jpg\");\n\n// Get metadata properties\nforestRef.GetMetadataAsync().ContinueWithOnMainThread(task =\u003e {\n if (!task.IsFaulted && !task.IsCanceled) {\n StorageMetadata meta = task.Result;\n // do stuff with meta\n }\n});\n```\n\nUpdate File Metadata\n\nYou can update file metadata at any time after the file upload completes by\nusing the `UpdateMetadataAsync` method which takes a `MetadataChange` object.\nRefer to the [full list](#file_metadata_properties) for more information on what\nproperties can be updated. Only the properties specified in the metadata are\nupdated, all others are left unmodified. \n\n```c#\n// Create reference to the file whose metadata we want to change\nStorageReference forestRef = storageRef.Child(\"images/forest.jpg\");\n\n// Create file metadata to update\nvar newMetadata = new MetadataChange();\nnewMetadata.CacheControl = \"public,max-age=300\";\nnewMetadata.ContentType = \"image/jpeg\";\n\n// Update metadata properties\nforestRef.UpdateMetadataAsync(newMetadata).ContinueWithOnMainThread(task =\u003e {\n if (!task.IsFaulted && !task.IsCanceled) {\n // access the updated meta data\n StorageMetadata meta = task.Result;\n }\n});\n```\n\nYou can delete writable metadata properties by passing the empty string: \n\n```c#\n// Create file metadata to update\nvar newMetadata = new MetadataChange();\nnewMetadata.ContentType = \"\";\n\n// Update metadata properties\nforestRef.UpdateMetadataAsync(newMetadata).ContinueWithOnMainThread(task =\u003e {\n if (!task.IsFaulted && !task.IsCanceled) {\n StorageMetadata meta = task.Result;\n // meta.ContentType should be an empty string now\n }\n});\n```\n\nHandle Errors\n\nThere are a number of reasons why errors may occur on getting or updating\nmetadata, including the file not existing, or the user not having permission\nto access the desired file. More information on errors can be found in the\n[Handle Errors](/docs/storage/unity/handle-errors)\nsection of the docs.\n\nCustom Metadata\n\nYou can specify custom metadata as a `Dictionary\u003cstring, string\u003e`. \n\n```c#\nvar newMetadata = new MetadataChange {\n CustomMetadata = new Dictionary\u003cstring, string\u003e {\n {\"location\", \"Yosemite, CA, USA\"},\n {\"activity\", \"Hiking\"}\n }\n};\n\n// UpdateMetadataAsync\n```\n\nYou can store app-specific data for each file in custom metadata, but we highly\nrecommend using a database (such as the\n[Firebase Realtime Database](/docs/database)) to store and synchronize this type of\ndata.\n\nFile Metadata Properties\n\nA full list of metadata properties on a file is available below:\n\n| Property | Type | Modifyable in MetadataChange |\n|----------------------|-----------------------|------------------------------|\n| `Bucket` | `string` | NO |\n| `Generation` | `string` | NO |\n| `MetadataGeneration` | `string` | NO |\n| `Path` | `string` | NO |\n| `Name` | `string` | NO |\n| `SizeBytes` | `long` | NO |\n| `CreationTimeMillis` | `long` | NO |\n| `UpdatedTimeMillis` | `long` | NO |\n| `CacheControl` | `string` | YES |\n| `ContentDisposition` | `string` | YES |\n| `ContentEncoding` | `string` | YES |\n| `ContentLanguage` | `string` | YES |\n| `ContentType` | `string` | YES |\n| `DownloadUrl` | `Uri` | NO |\n| `DownloadUrls` | `IList\u003cUri\u003e` | NO |\n| `CustomMetadataKeys` | `IEnumerable\u003cstring\u003e` | YES |\n\nNext Steps\n\nUploading, downloading, and updating files is important, but so is being able\nto remove them. Let's learn how to\n[delete files](/docs/storage/unity/delete-files)\nfrom Cloud Storage."]]