از ابرداده فایل با Cloud Storage در Flutter استفاده کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پس از آپلود یک فایل در مرجع Cloud Storage، همچنین می توانید ابرداده فایل را دریافت و به روز کنید، به عنوان مثال برای مشاهده یا به روز رسانی نوع محتوا. فایلها همچنین میتوانند جفتهای کلید/مقدار سفارشی را با فراداده فایل اضافی ذخیره کنند.
فراداده فایل را دریافت کنید
فراداده فایل حاوی ویژگیهای رایجی مانند name ، size ، و contentType (که اغلب به عنوان نوع MIME شناخته میشود) علاوه بر برخی موارد کمتر رایج مانند contentDisposition و timeCreated . این ابرداده را می توان با استفاده از متد getMetadata() از یک مرجع ذخیره سازی ابری بازیابی کرد.
// Create reference to the file whose metadata we want to retrievefinalforestRef=storageRef.child("images/forest.jpg");// Get metadata propertiesfinalmetadata=awaitforestRef.getMetadata();// Metadata now contains the metadata for 'images/forest.jpg'
به روز رسانی متادیتا فایل
با استفاده از متد updateMetadata() میتوانید پس از اتمام آپلود فایل، ابردادههای فایل را بهروزرسانی کنید. برای اطلاعات بیشتر در مورد ویژگی هایی که می توانند به روز شوند به لیست کامل مراجعه کنید. فقط ویژگیهای مشخصشده در فراداده بهروزرسانی میشوند، بقیه خصوصیات بدون تغییر باقی میمانند.
// Create reference to the file whose metadata we want to changefinalforestRef=storageRef.child("images/forest.jpg");// Create file metadata to updatefinalnewMetadata=SettableMetadata(cacheControl:"public,max-age=300",contentType:"image/jpeg",);// Update metadata propertiesfinalmetadata=awaitforestRef.updateMetadata(newMetadata);// Updated metadata for 'images/forest.jpg' is returned
شما می توانید ویژگی های ابرداده قابل نوشتن را با پاس کردن null حذف کنید:
// Delete the cacheControl propertyfinalnewMetadata=SettableMetadata(cacheControl:null);finalmetadata=awaitforestRef.updateMetadata(newMetadata);
رسیدگی به خطاها
دلایل متعددی وجود دارد که ممکن است هنگام دریافت یا بهروزرسانی فراداده، از جمله فایل موجود نباشد یا کاربر اجازه دسترسی به فایل مورد نظر را نداشته باشد، خطا رخ دهد. اطلاعات بیشتر در مورد خطاها را می توانید در بخش Handle Errors در اسناد پیدا کنید.
فراداده سفارشی
می توانید با استفاده از پارامتر customMetadata سازنده SettableMetadata ، ابرداده سفارشی را مشخص کنید:
// Create reference to the file whose metadata we want to changefinalforestRef=storageRef.child("images/forest.jpg");// Create file metadata to updatefinalnewCustomMetadata=SettableMetadata(customMetadata:{"location":"Yosemite, CA, USA","activity":"Hiking",},);// Update metadata propertiesfinalmetadata=awaitforestRef.updateMetadata(newCustomMetadata);// Updated metadata for 'images/forest.jpg' is returned
شما می توانید داده های خاص برنامه را برای هر فایل در ابرداده های سفارشی ذخیره کنید، اما ما به شدت توصیه می کنیم از یک پایگاه داده (مانند پایگاه داده بیدرنگ Firebase ) برای ذخیره و همگام سازی این نوع داده ها استفاده کنید.
ویژگی های فراداده فایل
لیست کاملی از ویژگی های ابرداده در یک فایل در زیر موجود است:
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-25 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\nAfter uploading a file to Cloud Storage reference, you can also get\nand update the file metadata, for example to view or update the content type.\nFiles can 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`, `size`, and\n`contentType` (often referred to as MIME type) in addition to some less\ncommon ones like `contentDisposition` and `timeCreated`. This metadata can be\nretrieved from a Cloud Storage reference using\nthe `getMetadata()` method. \n\n // Create reference to the file whose metadata we want to retrieve\n final forestRef = storageRef.child(\"images/forest.jpg\");\n\n // Get metadata properties\n final metadata = await forestRef.getMetadata();\n\n // Metadata now contains the metadata for 'images/forest.jpg'\n\nUpdate File Metadata\n\nYou can update file metadata at any time after the file upload completes by\nusing the `updateMetadata()` method. Refer to the\n[full list](#file-metadata-properties) for more information on what properties\ncan be updated. Only the properties specified in the metadata are updated,\nall others are left unmodified. \n\n // Create reference to the file whose metadata we want to change\n final forestRef = storageRef.child(\"images/forest.jpg\");\n\n // Create file metadata to update\n final newMetadata = SettableMetadata(\n cacheControl: \"public,max-age=300\",\n contentType: \"image/jpeg\",\n );\n\n // Update metadata properties\n final metadata = await forestRef.updateMetadata(newMetadata);\n\n // Updated metadata for 'images/forest.jpg' is returned\n\nYou can delete writable metadata properties by passing `null`: \n\n // Delete the cacheControl property\n final newMetadata = SettableMetadata(cacheControl: null);\n final metadata = await forestRef.updateMetadata(newMetadata);\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/flutter/handle-errors) section of the docs.\n\nCustom Metadata\n\nYou can specify custom metadata using the `customMetadata` parameter of the\n`SettableMetadata` constructor: \n\n // Create reference to the file whose metadata we want to change\n final forestRef = storageRef.child(\"images/forest.jpg\");\n\n // Create file metadata to update\n final newCustomMetadata = SettableMetadata(\n customMetadata: {\n \"location\": \"Yosemite, CA, USA\",\n \"activity\": \"Hiking\",\n },\n );\n\n // Update metadata properties\n final metadata = await forestRef.updateMetadata(newCustomMetadata);\n\n // Updated metadata for 'images/forest.jpg' is returned\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/overview)) 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 | Settable? |\n|----------------------|-----------------------|-----------|\n| `bucket` | `String` | No |\n| `generation` | `String` | No |\n| `metageneration` | `String` | No |\n| `metadataGeneration` | `String` | No |\n| `fullPath` | `String` | No |\n| `name` | `String` | No |\n| `size` | `int` | No |\n| `timeCreated` | `DateTime` | No |\n| `updated` | `DateTime` | No |\n| `md5Hash` | `String` | No |\n| `cacheControl` | `String` | Yes |\n| `contentDisposition` | `String` | Yes |\n| `contentEncoding` | `String` | Yes |\n| `contentLanguage` | `String` | Yes |\n| `contentType` | `String` | Yes |\n| `customMetadata` | `Map\u003cString, String\u003e` | Yes |\n\nUploading, downloading, and updating files is important, but so is being able\nto remove them. Let's learn how to [delete files](/docs/storage/flutter/delete-files)\nfrom Cloud Storage."]]