Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

E.5 Use File Metadata

Hadi Tavakoli edited this page Sep 26, 2018 · 2 revisions

Use File Metadata

After uploading a file to Firebase Storage reference, you can also get and update the file metadata, for example to view or update the content type. Files can also store custom key/value pairs with additional file metadata.

Note: By default, Firebase Storage buckets require Firebase Authentication to upload files. You can change your Firebase Storage Security Rules to allow unauthenticated access. Since the default Google App Engine app and Firebase share this bucket, configuring public access may make newly uploaded App Engine files publicly accessible as well. Be sure to restrict access to your Storage bucket again when you set up authentication.

Get File Metadata

File metadata contains common properties such as name, size, and contentType (often referred to as MIME type) in addition to some less common ones like contentDisposition and timeCreated. This metadata can be retrieved from a Firebase Storage reference using the getMetadata() method.

// Create a storage reference from our app
var rootRef:StorageReference = Storage.getReference();

// Get reference to the file
var imgRef:StorageReference = rootRef.child("images/img.jpg");

// you can read the metadata of any object on the Storage like this:
imgRef.getMetadata(onMetadataSuccess, onMetadataFailed);

function onMetadataFailed(e:StorageEvents):void
{
	trace("onMetadataFailed, errorCode = " + e.errorCode + " with message: " + e.msg);
}

function onMetadataSuccess(e:StorageEvents):void
{
	trace("bucket = " + 				e.metadata.bucket);
	trace("cacheControl = " + 			e.metadata.cacheControl);
	trace("contentDisposition = " + 	e.metadata.contentDisposition);
	trace("contentEncoding = " + 		e.metadata.contentEncoding);
	trace("contentLanguage = " + 		e.metadata.contentLanguage);
	trace("contentType = " + 			e.metadata.contentType);
	trace("creationTimeMillis = " + 	e.metadata.creationTimeMillis);
	trace("updatedTimeMillis = " + 		e.metadata.updatedTimeMillis);
	trace("customMetadata = " + 		e.metadata.customMetadata);
	trace("generation = " + 			e.metadata.generation);
	trace("metadataGeneration = " + 	e.metadata.metadataGeneration);
	trace("name = " + 					e.metadata.name);
	trace("path = " + 					e.metadata.path);
	trace("sizeBytes = " + 				e.metadata.sizeBytes);
}

Update File Metadata

You can update file metadata at any time after the file upload completes by using the updateMetadata() method. Only the properties specified in the metadata are updated, all others are left unmodified.

// Create a storage reference from our app
var rootRef:StorageReference = Storage.getReference();

// Get reference to the file
var imgRef:StorageReference = rootRef.child("images/img.jpg");

var metadata:StorageMetadata = new StorageMetadata([{var1:"Value1"}, {var2:"Value2"}], null, null, null, null, "image/jpg");
imgRef.updateMetadata(metadata, onMetadataUpdateSuccess, onMetadataUpdateFailed);

function onMetadataUpdateFailed(e:StorageEvents):void
{
	trace("onMetadataUpdateFailed with errorCode '" + e.errorCode + "' and msg: " + e.msg);
}

function onMetadataUpdateSuccess(e:StorageEvents):void
{
	trace("onMetadataUpdateSuccess");
}

Custom Metadata

You can specify custom metadata as an Array containing key/value objects as shown in the sample above.

var arr:Array = [];
arr.push({var1:"value1"});
arr.push({var2:"value2"});
arr.push({var3:"value3"});
...

Introduction to Firebase ANEs collection for Adobe Air apps


Get Started with Firebase Core in AIR

  1. Prerequisites
  2. Add Firebase to your app
  3. Add the Firebase SDK
  4. Init Firebase Core
  5. Available ANEs
  6. Managing Firebase iid

Get Started with Analytics

  1. Add Analytics ANE
  2. Init Analytics ANE
  3. Log Events
  4. Set User Properties

Get Started with Crashlytics

  1. Add Crashlytics ANE
  2. Test Your Implementation
  3. Customize Crash Reports
  4. Upload .dSYM for iOS apps

Get Started with DynamicLinks

  1. Add DynamicLinks ANE
  2. Init DynamicLinks ANE
  3. Create DynamicLinks
  4. Receive DynamicLinks
  5. View Analytics

Get Started with Authentication

  1. Add Authentication
  2. Init Authentication
  3. Manage Users
  4. Phone Number
  5. Custom Auth
  6. Anonymous Auth
  7. State in Email Actions
  8. Email Link Authentication

Get Started with FCM + OneSignal

  1. Add FCM ANE
  2. Init FCM ANE
  3. Send Your 1st Message
  4. Send Msg to Topics
  5. Understanding FCM Messages
  6. init OneSignal

Get Started with Firestore

  1. Add Firestore
  2. Init Firestore
  3. Add Data
  4. Transactions & Batches
  5. Delete Data
  6. Manage the Console
  7. Get Data
  8. Get Realtime Updates
  9. Simple and Compound
  10. Order and Limit Data
  11. Paginate Data
  12. Manage Indexes
  13. Secure Data
  14. Offline Data
  15. Where to Go From Here

Get Started with Realtime Database

  1. Add Realtime Database
  2. Init Realtime Database
  3. Structure Your Database
  4. Save Data
  5. Retrieve Data
  6. Enable Offline Capabilities

Get Started with Remote Config

  1. Parameters and Conditions
  2. Add Remote Config
  3. Init Remote Config

Get Started with Performance

  1. Add Performance ANE
  2. Init & Start Monitoring

Get Started with Storage

  1. Add Storage ANE
  2. Init Storage ANE
  3. Upload Files to Storage
  4. Download Files to Air
  5. Use File Metadata
  6. Delete Files

Get Started with Functions

  1. Write & Deploy Functions
  2. Add Functions ANE
  3. Init Functions
Clone this wiki locally