-
Notifications
You must be signed in to change notification settings - Fork 16
E.5 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.
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);
}
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");
}
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"});
...
Enjoy building Air apps – With ♥ from MyFlashLabs Team
Introduction to Firebase ANEs collection for Adobe Air apps
Get Started with Firebase Core in AIR
- Prerequisites
- Add Firebase to your app
- Add the Firebase SDK
- Init Firebase Core
- Available ANEs
- Managing Firebase iid
Get Started with Authentication
- Add Authentication
- Init Authentication
- Manage Users
- Phone Number
- Custom Auth
- Anonymous Auth
- State in Email Actions
- Email Link Authentication
Get Started with FCM + OneSignal
- Add FCM ANE
- Init FCM ANE
- Send Your 1st Message
- Send Msg to Topics
- Understanding FCM Messages
- init OneSignal
- Add Firestore
- Init Firestore
- Add Data
- Transactions & Batches
- Delete Data
- Manage the Console
- Get Data
- Get Realtime Updates
- Simple and Compound
- Order and Limit Data
- Paginate Data
- Manage Indexes
- Secure Data
- Offline Data
- Where to Go From Here
Get Started with Realtime Database
- Add Realtime Database
- Init Realtime Database
- Structure Your Database
- Save Data
- Retrieve Data
- Enable Offline Capabilities
Get Started with Remote Config
- Add Storage ANE
- Init Storage ANE
- Upload Files to Storage
- Download Files to Air
- Use File Metadata
- Delete Files