1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

B4J Question [ABMaterial] ABMUpload fires Page_FileUploaded twice upon failure (size)

Discussion in 'B4J Questions' started by OliverA, Aug 20, 2019.

  1. OliverA

    OliverA Expert Licensed User

    When uploading a file that is too large, Page_FileUploaded is invoked twice. Once by the catch block in ABMUploadHander. Another time through the Page_ParseEvent method of the page containing the ABMUpload component. I'm guessing that the ABMUpload component is issuing this call to the page (since I can't find anywhere else that is invoking Page_ParseEvent). The call from ABMUploadHandler has the FileName set to the LastException.Message and success set to False. The second call has the FileName set to the filename of the file that failed to upload and success set to False. Note: In Debug mode, the calls are reversed, with the Page_ParseEvent occurring before the call (via CallSubDelayed3) from ABMUploadHandler.

    Edit: Forgot to add: ABM v4.51
     
    Last edited: Aug 20, 2019
  2. Cableguy

    Cableguy Expert Licensed User

    What's your file size?
     
  3. OliverA

    OliverA Expert Licensed User

    I've set the size up to 500K, but uploaded files larger than that just to see what happens. I also ran the Demo (after this) and noticed that on failure (due to size) two chips would pop up, one stating "File java.lang.IllegalStateException: Request exceeds maxRequestSize (102400) not uploaded!" and then "File abcdefg.jpg not uploaded!". Please note that the ABMFileInput does not invoke Page_FileUploaded twice when the file size is too large.
     
  4. Cableguy

    Cableguy Expert Licensed User

    What would be the exact steps to reproduce this? I have a project in hands that will also need file uploading, and you got me worried
     
  5. OliverA

    OliverA Expert Licensed User

    Note: All this taken from the Demo program
    1) Add a couple of globals
    Code:
    Public DownloadFolder As String = "/www/" & ABMShared.AppName & "/uploads/"
    Public DownloadMaxSize As String = 500*1024
    2) Make sure the directory exists as set in #1
    3) In a ) WebSocket_Connected where it logs
    Code:
    Log("Websocket first connectoin")
    or b) if you use ConnectPage
    place the following code before page.Refresh (placement may not be important, I'm just following Demo code)
    Code:
    page.ws.session.SetAttribute("abmcallback", Me)
    page.ws.session.SetAttribute("abmdownloadfolder", DownloadFolder)
    page.ws.session.SetAttribute("abmmaxsize", DownloadMaxSize)
    4) Create an ABMUpload compenent and place it
    Sample code:
    Code:
    ' create the upload
    Dim upload As ABMUpload
    upload.Initialize(
    page"upload""Drop Here""Browse""")
    upl.Content.CellR(
    0,1).AddComponent(upload)
    5) Add you Page_FileUploaded method (to the same page the ABMUpload component is placed):
    Code:
    Sub Page_FileUploaded(FileName As String, success As Boolean)
       
    Log("Page_FileUploaded")
       
    If success Then
           
    Log($"${FileName} has been successflly uploaded"$)
       
    Else
           
    Log($"File ${FileName} not uploaded!"$)
       
    End If
    End Sub
    6) Enjoy the double call of Page_FileUploaded when the file size is too large
    If you are doing more than displaying a failure message, then it could be an issue (since you would duplicate your failure mitigation code). Otherwise you are just posting two notifications per failure.
     
  6. Cableguy

    Cableguy Expert Licensed User

    I'm done for today.
    I will try to reproduce this tomorrow and keep you posted
     
  7. alwaysbusy

    alwaysbusy Expert Licensed User

    Not a real bug in ABM. It is the second Try Catch that also calls Page_FileUploaded (on the line data = req.GetMultipartDate(downloadFolder, MaxSize)).
    You can remove the 'If SubExists(callback, "Page_FileUploaded") Then' if you want.

    Or, you can check the size first before running the GetMultipartData command:
    Code:
    ...
       
    If req.ContentLength > MaxSize Then
           resp.SendError(
    500"Error")
           
    Return
       
    End If

       
    Try
           data = req.GetMultipartData(downloadfolder, MaxSize)   
           ...
    This should call the Page_FileUploaded() only once.
     
    OliverA and Cableguy 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