B4J Tutorial [ABMaterial] Firebase Storage in 1.20

The next service you can use in WebApps using ABMaterial 1.20: Storage. With storage you can upload/download files with ease. Here is an example using it together with the new ABMFileInput component.

Usage:

B4X:
public Sub BuildPage()
  ...     
   ' NEW FIREBASE
  page.Firebase.ApiKey = "AIzaSyCS5-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  page.Firebase.AuthDomain = "project-xxxxxxxxxxxxxxxxxxxxxxxxxxx.firebaseapp.com"
  page.Firebase.DatabaseURL = "https://project-xxxxxxxxxxxxxxxxxxxxxxxx.firebaseio.com" 
  page.Firebase.StorageBucket = "project-xxxxxxxxxxxxxxxxxxxxxxx.appspot.com"
  ...      
End Sub

public Sub ConnectPage()
  ...
  ' create a ABMFileInput component so the user can pick a file from disk
   Dim inp1 As ABMFileInput
   inp1.Initialize(page, "inp1", "Select a file", "Open", True, "", "")   
   page.CellR(0,1).AddComponent(inp1)
   
   page.Refresh ' IMPORTANT
   
   ' NEW, because we use ShowLoaderType=ABM.LOADER_TYPE_MANUAL
   page.FinishedLoading 'IMPORTANT
End Sub

' the user has picked a file, so lets upload it to the storage
Sub inp1_Changed(value As String)
    Log("value : " & value)
    Dim inp1 As ABMFileInput  = page.Component("inp1")
    page.Firebase.Storage.Upload("UPLOAD", "images/hqdefault.jpg", inp1, "{contentType: 'image/jpeg'}")
End Sub

' file has been stored, we can retrieve the metadata or the download url (e.g. use in an ABMImage, or as a link in an ABMLabel)
Sub Page_FirebaseStorageResult(JobID As String, extra As String)
    Log(extra)
    Select Case JobID
        Case "UPLOAD"
            page.Firebase.Storage.GetDownloadUrl("GETDOWNLOADURL", "images/hqdefault.jpg")           
        Case "GETDOWNLOADURL"
            page.Firebase.Storage.GetMetaData("GETMETADATA","images/hqdefault.jpg")
        Case "GETMETADATA"
            Dim inp1 As ABMFileInput  = page.Component("inp1")
            inp1.Clear
    End Select   
End Sub

Sub Page_FirebaseStorageError(JobID As String, extra As String)
    log("Error: " & extra & " for job: " & JobID)
End Sub
 

Harris

Expert
Licensed User
Longtime User
Can I use this when not connected to the internet (local server with no internet connection)?
Thanks
 

Harris

Expert
Licensed User
Longtime User
No, this is a cloud solution.
Ok, for next project then...
I got most of what I need for localhost, and seems to be working well to date...

Will keep posted if any issues.

Thanks
 
Top