B4J Question File upload problem when using iframe in Chrome and Edge (CallSubDelayed2?)

hcm

Member
Licensed User
Longtime User
Hi everyone,
I have been stuck for a while: in a Websocket Application I need to upload an image file (<1MB) from the client browser. I used the file upload example for this purpose.
The upload works great in all browsers when running it in the browser directly, but it fails in Chrome and Edge when it runs in an iframe.
In Firefox it surprisingly works in an iframe though.

In the Console log I can see that all browsers think that the transfer was successfull (console.log "done"). Transfer is done by a XMLHttpRequest():

JavaScript:
                    var fd = new FormData();
                    fd.append("gmappic", file);

                    var xhr = new XMLHttpRequest();
                    xhr.open("POST", path, true);//true=async
   
                    xhr.onload = function () {
                        console.log("done");  
                      };
                    xhr.onerror = function () {
                          console.error("Error", xhr.statusText);
                      };
                     
                    xhr.send(fd);

Also on the B4J side the "Getting upload" message is shown in the log, but then it never jumps to the "FileUploaded" Sub.
It only reaches the "FileUploaded" Sub, when not running the application in an iframe.

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
   
    If req.Method = "GET" Then
        '...
    Else
        'get the callback module from the session (multiple modules can use this handler)
        Dim callback As Object = req.GetSession.GetAttribute("file_upload_sender")
        Try
            Log("Getting upload: " & req.ContentType)
            Dim data As Map = req.GetMultipartData(File.DirApp & "/www/uploads/" , 10000000)
            CallSubDelayed2(callback, "FileUploaded", data) '<- FileUploaded is never reached when upload goes through an iframe'
        Catch
            Log("File error")
            CallSubDelayed2(callback, "FileError", LastException.Message)
            resp.SendError(500, LastException.Message)
        End Try
    End If
       
End Sub

Can this be a problem of the CallSubDelayed2 function?

Any help would be highly appreciated!
Christoph
 
Last edited:
Solution
I solved it by eliminating the CallSubDelayed2- but I have no clue why this was a problem when the file was uploaded through an iframe

hcm

Member
Licensed User
Longtime User
I solved it by eliminating the CallSubDelayed2- but I have no clue why this was a problem when the file was uploaded through an iframe
 
Upvote 0
Solution
Top