از ابرداده فایل با Cloud Storage for Unity استفاده کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پس از آپلود فایل در مرجع Cloud Storage ، همچنین می توانید متادیتای فایل را دریافت و به روز کنید، به عنوان مثال برای به روز رسانی نوع محتوا. فایلها همچنین میتوانند جفتهای کلید/مقدار سفارشی را با فراداده فایل اضافی ذخیره کنند.
فراداده فایل را دریافت کنید
فراداده فایل حاوی ویژگیهای رایجی مانند Name ، SizeBytes ، و ContentType (اغلب به عنوان نوع MIME شناخته میشود) علاوه بر برخی موارد کمتر رایج مانند ContentDisposition و CreationTimeMillis است. این ابرداده را می توان با استفاده از روش GetMetadataAsync از یک مرجع Cloud Storage بازیابی کرد.
// 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}});
رسیدگی به خطاها
دلایل متعددی وجود دارد که ممکن است هنگام دریافت یا بهروزرسانی فراداده، از جمله فایل موجود نباشد یا کاربر اجازه دسترسی به فایل مورد نظر را نداشته باشد، خطا رخ دهد. اطلاعات بیشتر در مورد خطاها را می توانید در بخش Handle Errors در اسناد پیدا کنید.
فراداده سفارشی
میتوانید ابردادههای سفارشی را بهعنوان 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-09-03 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-09-03 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]