Cloud Storage 참조로 파일을 업로드한 후 파일 메타데이터를 가져오거나
업데이트할 수 있습니다. 예를 들어 콘텐츠 유형을 확인 또는 업데이트할 수 있습니다.
또한 추가 파일 메타데이터로 커스텀 키-값 쌍을 저장할 수 있습니다.
파일 메타데이터 가져오기
파일 메타데이터는 name, size, contentType(통칭 MIME 유형) 등의 일반적인 속성뿐 아니라 contentDisposition 및 timeCreated 등의 비일반적 속성도 포함합니다. getMetadata() 메서드를 사용하여 Cloud Storage 참조에서 이러한 메타데이터를 가져올 수 있습니다.
// 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);
오류 처리
메타데이터를 가져오거나 업데이트할 때 오류가 발생하는 데에는 파일이 없거나 파일에 대한 액세스 권한이 없는 경우 등 다양한 이유가 있습니다. 오류의 자세한 내용은 문서의 오류 처리 섹션을 참조하세요.
커스텀 메타데이터
SettableMetadata 생성자의 customMetadata 파라미터를 사용하여 커스텀 메타데이터를 지정할 수 있습니다.
// 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 실시간 데이터베이스 같은 데이터베이스를 사용하는 것이
좋습니다.
파일 메타데이터 속성
파일 메타데이터 속성의 전체 목록은 다음과 같습니다.
속성
유형
설정 가능 여부
bucket
String
아니요
generation
String
아니요
metageneration
String
아니요
metadataGeneration
String
아니요
fullPath
String
아니요
name
String
아니요
size
int
아니요
timeCreated
DateTime
아니요
updated
DateTime
아니요
md5Hash
String
아니요
cacheControl
String
예
contentDisposition
String
예
contentEncoding
String
예
contentLanguage
String
예
contentType
String
예
customMetadata
Map<String, String>
예
파일 업로드, 다운로드, 업데이트도 중요하지만 파일을 지우는 것도 가능해야 합니다. Cloud Storage에서 파일을 삭제하는 방법을 알아보세요.
[[["이해하기 쉬움","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-14(UTC)"],[],[],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\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."]]