Storage Use File Metadata - tuarua/Firebase-ANE GitHub Wiki

The contents of this page are based on the original Firebase Documentation

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

Note: By default, Cloud Storage buckets require Firebase Authentication to upload files. You can change your Firebase Security Rules for Cloud Storage 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 Cloud Storage reference using the getMetadata method.

// Create reference to the file whose metadata we want to retrieve
var forestRef:StorageReference = storageRef.child("images/forest.jpg");
// Get metadata properties
forestRef.getMetadata(function (metadata:StorageMetadata, error:StorageError):void {

});

Update File Metadata

You can update file metadata at any time after the file upload completes by using the updateMetadata method. Refer to the full list for more information on what properties can be updated. Only the properties specified in the metadata are updated, all others are left unmodified.

// Create file metadata to update
var newMetadata:StorageMetadata = new StorageMetadata();
newMetadata.cacheControl = "public,max-age=300";
newMetadata.contentType = "image/jpeg";
storageRef.updateMetadata(newMetadata, function (error:StorageError):void {
    
});

You can delete writable metadata properties by passing the empty string:

var newMetadata:StorageMetadata = new StorageMetadata();
newMetadata.contentType = "";
storageRef.updateMetadata(newMetadata, function (error:StorageError):void {
    
});

Custom Metadata

You can specify custom metadata as an Object containing String properties.

newMetadata.customMetadata = {
    "location": "Yosemite, CA, USA",
    "activity": "Hiking"
};