B4J Library [ABMaterial]: Attempting a file chooser

Discussion in 'B4J Libraries & Classes' started by Mashiane, Jul 23, 2018.

  1. Mashiane

    Mashiane Expert Licensed User

    Ola

    Goal: Ability to upload files to the server, after the files are uploaded, clear the list of files to start all over again.

    MashAttachments.gif

    The original source code is available here.

    In Class_Globals

    Code:
    Dim ma As MashAttachments
        
    Dim uploads As Int = 0   'IMPORTANT
    uploads is necessary to keep the number of files uploaded. As soon as the number of files uploaded matches, then you can clear the control. Clearing the component is necessary because doing another upload does not clear the file list after upload. This is a known issue. When the file list is cleared, the default title is also reset (see gif above)


    In ConnectPage

    Code:
    ma.Initialize(page,"ma","Select file(s)...",True)
    ma.ZDepth = ABM.ZDEPTH_1
        
    page.Cell(1,1).AddComponent(ma.ABMComp)
    No external dependencies needed. Explaing the initialize method...

    • "Select files(s)..." title to appear, you can have this blank if you dont want it to show.
    • True - boolean to turn multi-file selection on or off.
    Events

    We call the .Upload method just after the change event of the control is fired.

    Code:
    'upload a file as soon as its selected
    Sub ma_changed(value As Map)
        
    'reset the number of files to upload to the server
        uploads = 0  'IMPORTANT
        'upload files to the server
        ma.upload
    End Sub

    'we can detect the progress of the file uploaded
    Sub ma_progress(value As Map)
        
    Dim files As String = value.Get("value")
        
    Log(files)
    End Sub

    'when the file upload is complete
    Sub ma_complete(value As Map)
        
    Dim files As String = value.Get("value")
        
    Log(files)
    End Sub
    other events

    _progress, _complete, _error, _abort

    For Page_FileUploaded, we increment uploads when a file is uploaded
    when .GetCount = uploads, we clear the control to enable another upload.

    Code:
    Sub Page_FileUploaded(FileName As String, success As Boolean)
        myToastId = myToastId + 
    1
        
    If success Then
            
    page.ShowToast("toast" & myToastId, "toastgreen""File " & FileName & " uploaded!"3000False)
            uploads = uploads + 
    1
        
    Else
            
    page.ShowToast("toast" & myToastId, "toastred""File " & FileName & " not uploaded!"3000False)
        
    End If
        
    Dim actualFile As String = File.combine(File.DirApp, DownloadFolder & FileName)
        
    page.ws.Flush ' IMPORTANT
        
        
    'if we have uploaded enough files, clear
        If mu.GetCount = uploads Then
            mu.clear
        
    End If
        
        
    'if we have uploaded enough files, clear
        If ma.GetCount = uploads Then
            ma.clear
        
    End If
        
    End Sub

    To do (perhaps)

    • Ability to change the colors

    Ta!

    Enjoy...
     

    Attached Files:

    Last edited: Jul 23, 2018
    joulongleu and Don Oso like this.
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