B4J Question ABMaterial Firebase

wangondu

Member
Licensed User
Longtime User
hey,

Am trying to run the firebase sample of code provided on demo but am getting this error

"Error: storage/unknown for job: UPLOAD
B4X:
'Class module
Sub Class_Globals
    Private ws As WebSocket 'ignore
    ' will hold our page information
    Public page As ABMPage
    ' page theme
    Private theme As ABMTheme
    ' to access the constants
    Private ABM As ABMaterial 'ignore
    ' name of the page, must be the same as the class name (case sensitive!)
    Public Name As String = "firebaser"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = ""
    ' your own variables

   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    ' build the local structure IMPORTANT!
    BuildPage
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    '----------------------MODIFICATION-------------------------------
    Log("Connected")
    ws = WebSocket1
    ABMPageId = ABM.GetPageID(page, Name,ws)
    page.Firebase.CheckAuthorized
    Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds)
   
    If ABMShared.NeedsAuthorization Then
        If session.GetAttribute2("IsAuthorized", "") = "" Then
            ABMShared.NavigateToPage(ws, ABMPageId, "../")
            Return
        End If
    End If
   
    ABM.UpdateFromCache(Me, ABMShared.CachedPages, ABMPageId, ws)
    If page.ComesFromPageCache Then
        ' when we have a page that is cached it doesn't matter if it comes or not from a new connection we serve the cached version.
        Log("Comes from cache")
        page.Refresh
        page.FinishedLoading
    Else
        If page.WebsocketReconnected Then
            Log("Websocket reconnected")
            ' when we have a client that doesn't have the page in cache and it's websocket reconnected and also it's session is new - basically when the client had internet problems and it's session (and also cache) expired before he reconnected so the user has content in the browser but we don't have any on the server. So we need to reload the page.
            ' when a client that doesn't have the page in cache and it's websocket reconnected but it's session is not new - when the client had internet problems and when he reconnected it's session was valid but he had no cache for this page we need to reload the page as the user browser has content, reconnected but we have no content in cache
            ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName)
        Else
            ' when the client did not reconnected it doesn't matter if the session was new or not because this is the websockets first connection so no dynamic content in the browser ... we are going to serve the dynamic content...
            Log("Websocket first connection")
            page.Prepare
            ConnectPage
        End If
    End If
    Log(ABMPageId)
       
    '----------------------MODIFICATION-------------------------------
End Sub

Private Sub WebSocket_Disconnected
    Log("Disconnected")
End Sub

Sub Page_ParseEvent(Params As Map)
    Dim eventName As String = Params.Get("eventname")
    Dim eventParams() As String = Regex.Split(",",Params.Get("eventparams"))
    'Log(eventName)
    If eventName = "beforeunload" Then
        Log("preparing for url refresh")
        ABM.RemoveMeFromCache(ABMShared.CachedPages, ABMPageId)
        Return
    End If
    Log("Params.Size: " & Params.Size)
    If Params.Size = 3 Then
        Log("Param: " & Params.Get(eventParams(0)))
    End If
    If SubExists(Me, eventName) Then
        Params.Remove("eventname")
        Params.Remove("eventparams")
       
        Select Case Params.Size
            Case 0
                CallSub(Me, eventName)
            Case 1
                CallSub2(Me, eventName, Params.Get(eventParams(0)))
            Case 2
                If Params.get(eventParams(0)) = "abmistable" Then
                    Dim PassedTables As List = ABM.ProcessTablesFromTargetName(Params.get(eventParams(1)))
                    CallSub2(Me, eventName, PassedTables)
                Else
                    CallSub3(Me, eventName, Params.Get(eventParams(0)), Params.Get(eventParams(1)))
                End If
            Case Else
                ' cannot be called directly, to many param
                CallSub2(Me, eventName, Params)
        End Select
    End If
End Sub

public Sub BuildTheme()
    ' start with the base theme defined in ABMShared
    theme.Initialize("pagetheme")
    theme.AddABMTheme(ABMShared.MyTheme)
   
    ' add extra page specific theme stuff
End Sub

public Sub BuildPage()
    ' initialize the theme
    BuildTheme
   
    ' initialize this page using our theme
    page.InitializeWithTheme(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, theme)
    page.ShowLoader=True
    page.PageHTMLName = "index.html"
    page.PageTitle = ""
    page.PageDescription = ""
    page.PageKeywords = ""
    page.PageSiteMapPriority = ""
    page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
       
    page.ShowConnectedIndicator = True
    ' add fire base
    page.Firebase.ApiKey ="AIzaSyBmqLtIEUtqv9GFUfIkViZkOMpDVfhIi-Y"
    page.Firebase.AuthDomain ="evansgitonga-806b3.firebaseapp.com"
    page.Firebase.DatabaseURL ="https://evansgitonga-806b3.firebaseio.com"
    page.Firebase.StorageBucket = "/evansgitonga-806b3.appspot.com"
    ' adding a navigation bar
    ABMShared.BuildNavigationBar(page, "Title","../images/logo.png", "", "", "")
           
    ' create the page grid
    page.AddRowsM(4,True,0,0, "").AddCellsOS(2,0,0,0,12,6,6,"")
    page.AddRow(1,True,"","")
    page.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
       
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
    ' refresh the page
    page.Refresh
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition
   
End Sub

Sub inp1_Changed(value As String)
    ' the user has picked a File, so lets upload it To the storage
    Log("value : " & value)
    Dim inp1 As ABMFileInput = page.Component("inp1")
   
    page.Firebase.Storage.Upload("UPLOAD", "images/slider4.jpg", inp1, "{contentType: 'image/jpeg'}")
'    page.Firebase.Storage.
    End Sub
' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
    ' saving the navigation bar position
    page.SaveNavigationBarPosition
    If Action = "LogOff" Then
        ABMShared.LogOff(page)
        Return
    End If

    ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub
Sub Page_FirebaseStorageResult(JobID As String, extra As String)
    ' 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)
    Log(extra)
    Select Case JobID
        Case "UPLOAD"
            page.Firebase.Storage.GetDownloadUrl("GETDOWNLOADURL", "images/slider4.jpeg")
        Case "GETDOWNLOADURL"
            page.Firebase.Storage.GetMetaData("GETMETADATA","images/slider4.jpeg")
        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
Sub Page_MsgboxResult(returnName As String, result As String)
   
End Sub

Sub Page_InputboxResult(returnName As String, result As String)
   
End Sub

Sub Page_DebugConsole(message As String)
    Log("---> " & message)
End Sub

Sub Page_FileUploaded(FileName As String, success As Boolean)
   
End Sub

Sub Page_ToastClicked(ToastId As String, Action As String)
       
End Sub

Sub Page_ToastDismissed(ToastId As String)
   
End Sub

Sub Page_Authenticated(Params As Map)
   
End Sub
Sub Page_FirebaseAuthStateChanged(IsLoggedIn As Boolean)
    Log(IsLoggedIn)
    If IsLoggedIn Then
        page.Firebase.Auth.CurrentUser.UpdateFromBrowser'  IMPORTANT
        Log("ProviderId: " & page.Firebase.Auth.CurrentUser.ProviderId)
        Log("ProviderData: " & page.Firebase.Auth.CurrentUser.ProviderData.Size)
    Else
        Log("Authorizing...")
        page.Firebase.Auth.SignInWithGoogle(False)
    End If
End Sub

Sub Page_FirebaseAuthError(extra As String)
    Log(extra)
End Sub






Sub Page_ModalSheetDismissed(ModalSheetName As String)
   
End Sub

Sub Page_NextContent(TriggerComponent As String)
   
End Sub

Sub Page_SignedOffSocialNetwork(Network As String, Extra As String)
   
End Sub

Sub page_CellClicked(Target As String, RowCell As String)
    'Log(Target)
End Sub

Sub page_RowClicked(Target As String, Row As String)
    'Log(Target)
End Sub

Sub Page_NativeResponse(jsonMessage As String)
   
End Sub

Sub Page_NavigationbarSearch(search As String)
   
End Sub
"
 
Top