I'm trying to implement a file upload from my device to a Web API and Encode from image.
And Error encounter is as below:-
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.InitializePost2(java.lang.String, byte[])' on a null object reference
at anywheresoftware.b4a.samples.httputils2.httpjob._postbytes(httpjob.java:284)
at anywheresoftware.b4a.samples.httputils2.httpjob._poststring(httpjob.java:423)
And Error encounter is as below:-
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.InitializePost2(java.lang.String, byte[])' on a null object reference
at anywheresoftware.b4a.samples.httputils2.httpjob._postbytes(httpjob.java:284)
at anywheresoftware.b4a.samples.httputils2.httpjob._poststring(httpjob.java:423)
B4X:
Private Base64Con As Base64Image
PicFileName=IS001.jpeg
Private B64Str As String = Base64Con.EncodeFromImage(File.DirDefaultExternal, "IS001.jpeg")
Dim json As HttpJob
Dim m As String = $"?DocNo=${DocNo}&PicFileName=${PicFileName}&PicImage=${B64Str}"$
json.PostString(Starter.URILink & "/api/Customer/UploadDocument" & m,"")
json.GetRequest.SetHeader("Authorization","Bearer " & kvs.GetSimple("CurrUserTokenAccess"))
json.GetRequest.SetContentType("application/json")
Wait For (json) JobDone(json As HttpJob)
If json.Success Then
Log("dd:" & json.GetString)
Dim jNDparser As JSONParser
jNDparser.Initialize(json.GetString)
Dim root As Map = jNDparser.NextObject
Dim result As String = root.Get("result")
Dim data As String = root.Get("data")
Dim resultset As String = root.Get("resultset")
Log("data:" & data.Trim)
If data.Trim ="Successful" Then
str="UPDATE Photo SET ImageSync='Y' "
str=str & " WHERE Docno='" & DocNo & "' "
SQL1.ExecNonQuery(str)
End If
End If
json.Release