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

E.2 Init Storage

myflashlab edited this page Sep 6, 2016 · 1 revision

Initialize Firebase Storage

You can initialize the Storage by calling Storage.init(); As soon as you initialized the firebaseStorage.ane in your project, you will be ready to create references to different locations of your storage.

Your files are stored in a Firebase Storage bucket. The files in this bucket are presented in a hierarchical structure, just like the file system on your local hard disk, or the data in the Firebase Realtime Database. By creating a reference to a file, your app gains access to it. These references can then be used to upload or download data, get or update metadata or delete the file. A reference can either point to a specific file or to a higher level in the hierarchy.

If you've used the Firebase Realtime Database, these paths should seem very familiar to you. However, your file data is stored in Google Cloud Storage, not in the Realtime Database.

NOTE: Make sure you have already initialized the Firebase core before trying any other Firebase child ANEs.

Create a Reference

Create a reference to upload, download, or delete a file, or to get or update its metadata. A reference can be thought of as a pointer to a file in the cloud. References are lightweight, so you can create as many as you need. They are also reusable for multiple operations.

References are created from the Storage class on your Firebase app by calling the getReference method. The getReference method accepts different forms of inputs which you can use to create references to the root or a child location in the storage.

// create a storage reference from URL
var storageRef:StorageReference = Storage.getReference(null, "gs://your-storage.appspot.com");

// create a storage reference to the root like above
var storageRef:StorageReference = Storage.getReference();

You can create a reference to a location lower in the tree, say 'images/space.jpg', by using the child method on an existing reference.

// Create a child reference. spaceRef now points to "space.jpg"
var spaceRef:StorageReference = storageRef.child("images/space.jpg");

// References can be chained together multiple times. earthRef points to "images/earth.jpg"
var earthRef:StorageReference = spaceRef.parent.child("earth.jpg");

// nilRef is null, since the parent of root is null
var nilRef:StorageReference = spaceRef.root.parent;

Reference Properties

You can inspect references to better understand the files they point to using the path, name, and bucket properties. These properties get the file's full path, name, and bucket.

trace(spaceRef.path); // "images/space.jpg"
trace(spaceRef.name); // "space.jpg"
trace(spaceRef.bucket); // name of the storage bucket that the files are stored in

Limitations on References

Reference paths and names can contain any sequence of valid Unicode characters, but certain restrictions are imposed including:

  1. Total length of reference.fullPath must be between 1 and 1024 bytes when UTF-8 encoded.
  2. No Carriage Return or Line Feed characters.
  3. Avoid using #, [, ], *, or ?, as these do not work well with other tools such as the Firebase Realtime Database or gsutil.

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