B4A Library FirebaseStorage - Simple file storage backend

Status
Not open for further replies.
FirebaseStorage service is similar to a FTP server. Clients can upload and download files.
FirebaseStorage takes it a step further and adds an authorization layer.

Google are offering a free package and a paid package: https://firebase.google.com/pricing/
The free offer is quite generous.

FirebaseStorage works together with FirebaseAuth for the access control.

The rules are set in Firebase console. I recommend to start with these rules (make sure to update the service in the second line based on your app id):
B4X:
service firebase.storage {
  match /b/b4a-test1.appspot.com/o {
  match /auth/{allPaths=**} {
     allow read, write: if request.auth != null;
   }
  match /public/{allPaths=**} {
  allow read;
  }
  match /user/{userId}/{allPaths=**} {
  allow read, write: if request.auth.uid == userId;
  }

  }
}

With these rules there are three accessible folders with the following access levels:
/public - Anyone can read from this folder. You can upload files to this folder from the console. This is a good place for any general files (images, data sets). Note that these files can be accessed from outside your app.
/auth - All authenticated users can read and write to this folder. Resources limited to the app users.
/user/{userId} - Only the user can access this folder. User's private resources.
Subfolders will have the same access control as their parent folders.

Setup instructions

Follow the Firebase integration instructions: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/#content
Add the Auth snippet as well as the base snippets.

The code is simple. You need to initialize FirebaseStorage, preferably from the Starter service, with your bucket url. You can find it in Firebase console (gs://...):

SS-2016-06-26_14.56.07.png


You can now upload and download files and also get the available metadata.
All the methods are asynchronous which means that an event is raised when the operation completes. The events will be raised in the same module that started the operation.

Note that you can use FirebaseStorage without FirebaseAuth and then use it to download files from the public folder.
 

Attachments

  • StorageExample.zip
    24.7 KB · Views: 1,288
Last edited:
D

Deleted member 103

Guest
My app allows auth with Google. But not the other auth methods... Did you allow one of these settings???
Yes, I have exactly the same settings.
 

Alpandino

Member
Licensed User
Hi, is there any way to move a file from a remote folder to another remote folder without download first the file on a locale folder? I've found this link that talk about a similar function in Google Cloud Storage's API.
Is it possible integrate this function in B4A?
 

konradwalsh

Active Member
Licensed User
Longtime User
QUESTION:
How do you consume the GetMetadata


Never mind me.. I just thought about reading the XML file and just learned some valuable information
This is the code for anyone else needing it..


B4X:
Private Sub Storage_MetadataCompleted (Metadata As StorageMetadata, Success As Boolean)
   Log("Time : " & Metadata.Timestamp)
      Log("Name : " & Metadata.Name)
         Log("Path : " & Metadata.Path)
            Log("Size : " & Metadata.Size)
End Sub
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
Thanks for this wonderful library @Erel.

Only a couple of questions:

1) no specific manifest snippet for this Firebase library ?
2) "/auth - All authenticated users can read and write to this folder. Resources limited to the app users." ---> Do you mean google user account registered within the android phone? Like user@gmail.com ?
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
My need is to manage files of my Play Store app using a group logic.

For example:
Users within group A (customer A) can share upload / download the group A files and cannot access the files within others groups within the same app.
Users within group B (customer B) can upload / download files within group B and cannot access the files within others groups within the same app.

A Group (folder?) is created programmatically within the Android App for each customer user.

Is it possible to manage this scenario with firebase storage API and Firebase Auth?
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
How do you implement the groups? Who do you decide which customers belong to the same group?

There is a customer responsible for each customer that manage a team (coworkers).
Actually all users (resp & coworkers) share the same App* UI (workers UI and Responsible UI within the same App).

*Play Store App
 

luke2012

Well-Known Member
Licensed User
Longtime User
Can I create the unique path using firebase rest api (programmatically) within the App ?
 
Last edited:

johndb

Active Member
Licensed User
Longtime User
Are there any future plans to release a B4J version of the FirebaseStorage library and other Firebase libraries?
 

DonManfred

Expert
Licensed User
Longtime User
Thanks for the information but @alwaysbusy appears to provide the Firebase services within his ABmaterial framework
Ask him which api jar he use ;)
I guess it is the java-server-sdk 3.x

Edit: seems to be using javascript (have had a look at the v2 release email i got)
 
Last edited:
Status
Not open for further replies.
Top