B4J Question Upload jpg/mp4 to Websocket fileupload

Nizze

Active Member
Licensed User
Hi

I use Erels example for B4J for http upload
I use this code for uploading a jpg that i found in the forum here to upload to server with a PHP script.
It works on a server with apache

No i want to have it running with B4J

this is the code from the android client:

B4X:
Sub PhotoUpload(filname As String)
    Log("PhotoUpload " & filname)

    PostPath = "http://www.xxxxx.se:81/websocket_with_fileupload/index.html"
    Dim j As HttpJob
    Dim img As String = filname '"1.jpg"
    j.Initialize("", Me)
    Dim mp As MultipartFileData
    mp.Initialize
    mp.Dir = rp.GetSafeDirDefaultExternal("")
    mp.FileName = img
    mp.KeyName = "file"
    mp.ContentType = "image/jpg"
    j.PostMultipart(PostPath, Null, Array(mp))
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log("- - - - - - - - - - - - - ")
        Log(j.GetString)
        If img = j.GetString Then
            ToastMessageShow("Kort upladdat.", False)
        Else
            ToastMessageShow("Fel vid uppladdning", False)
        End If
    End If
    j.Release
    
End Sub
and the log from the server :

Start success: true
(Rect)(0, 0, 3264, 2448)
Picture taken: (Bitmap): 1920 x 1080, scale = 1,00
Photo dir /storage/emulated/0/Android/data/nn.test/files
Doning 2.jpg
- - - - - - - - - - - - -
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Upload tool </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="index.css" />
<script src="/b4j_ws.js"></script>
<script src="jquery.form.min.js"></script>
</head>
<body>
<h1>Upload tool </h1>
<form id="form1" action="filehelper" method="post" enctype="multipart/form-data">
<label for="file">Välj fil (max storlek 1Gb):</label>
<input type="file" name="file1">
<input type="submit" name="submit" value="Submit">
</form>
<p id="result"></p>
<script>
$( document ).ready(function() {
b4j_connect("/websocket_with_fileupload/ws");
});
</script>
~l6820119569:
</body>
What can i do to get upload to work ?
And if i try to upload an .Mp4 file , i dont get anything in the log
eveen if i change mp.ContentType = "image/jpg" to mp.ContentType = "video/mp4"

Br
Nizze
 

Nizze

Active Member
Licensed User
Top