B4J Tutorial [ABMaterial] Firebase Storage in 1.20

Discussion in 'B4J Tutorials' started by alwaysbusy, Jun 16, 2016.

  1. alwaysbusy

    alwaysbusy Expert Licensed User

    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:

    Code:
    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
     
  2. Harris

    Harris Well-Known Member Licensed User

    Can I use this when not connected to the internet (local server with no internet connection)?
    Thanks
     
  3. alwaysbusy

    alwaysbusy Expert Licensed User

    No, this is a cloud solution.
     
  4. Harris

    Harris Well-Known Member Licensed User

    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice