Bug? OkHttpUtils2: Multipart and Job.GetString Bug: FileNotFoundException

Status
Not open for further replies.

Ferdari

Active Member
Licensed User
Longtime User
I was about to throw the job and getting crazy, searching for solution in every corner of the forum.

thinking that the ContentChooser was the problem, trying every solution posted:
B4X:
        j.Initialize( "j", Me)
        Dim fd As MultipartFileData
        fd.Initialize
        fd.KeyName = "img"
        fd.Dir = File.DirInternalCache
        fd.FileName = "sometempfile.jpg"
        fd.ContentType = "image/jpg"
        j.PostMultipart("http://server.net", CreateMap("param1": "value1","":"","":""), Array(fd))
        if j.success then
            log(j.getString)
        end if

I always getting error:
B4X:
java.io.FileNotFoundException: open failed: ENOENT (No such file or directory).....
....

The problem was not the file or the path, it was this simple code:
Job.GetString or j.GetString
when deleted all works more than fine.

I think this is a bug, because the error at log its not related to file.

I LOST ABOUT 4 HOURS TRYING TO SOLVE THIS, I HOPE THIS HELPS ANYONE.
 

OliverA

Expert
Licensed User
Longtime User
j.PostMultipart("http://server.net", CreateMap("param1": "value1","":"","":""), Array(fd))
if j.success then
log(j.getString)
end if
Even without Wait For, this is wrong. Without using Wait For, you should have had a JobDone sub declared in your module as per https://www.b4x.com/android/forum/t...-services-are-now-even-simpler.18992/#content. Also, the B4A user's guide (version 1.7) (https://www.b4x.com/android/forum/threads/users-guide.15861/#content) states on page 124 that "The calling module must contain a JobDone routine where you handle the results of the different jobs."
 

Ferdari

Active Member
Licensed User
Longtime User
No bug here. You are not using OkHttpUtils2 correctly.

[B4X] OkHttpUtils2 with Wait For

Use Wait For as explained above or handle the JobDone event.

But why the error pointed to FileNotFoundException? and not j.getstring or something that points to the real ERROR
the file was correct, and if the log told the real problem hours can be saved.
B4X:
java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)

Even without Wait For, this is wrong. Without using Wait For, you should have had a JobDone sub declared in your module as per https://www.b4x.com/android/forum/t...-services-are-now-even-simpler.18992/#content. Also, the B4A user's guide (version 1.7) (https://www.b4x.com/android/forum/threads/users-guide.15861/#content) states on page 124 that "The calling module must contain a JobDone routine where you handle the results of the different jobs."

i noticed when resolved the j.getString problem, the log pointed to the wrong direction. the next error was the sub JobDone and solved just in minutes. the problem was the FileNotFoundException Bug.
 

OliverA

Expert
Licensed User
Longtime User
the problem was the FileNotFoundException Bug.
It is not a bug. You either use Wait For or JobDone with HTTPJob. If you do not, then you are accessing stuff before the "job" even gets done. You are accessing a variable that is in the process of being set. So yeah, it's going to bomb out. That is not an error, since you are accessing something that has not finished processing yet.
 

Ferdari

Active Member
Licensed User
Longtime User
Even if i put job.GetString in JobDone Sub it has error:

B4X:
Sub SendDefio_Click
    If title.Text <> "" Then
        ProgressDialogShow2("Cargando", False)
      
        j.Initialize( "j", Me)
        Dim fd As MultipartFileData
        fd.Initialize
        fd.KeyName = "img"
        fd.Dir = File.DirInternalCache
        fd.FileName = "sometempfile.jpg"
        fd.ContentType = "image/jpg"
        j.PostMultipart("http://defio.net", CreateMap("param1": "value1","":"","":""), Array(fd))
      

    End If
End Sub

Sub JobDone(job As HttpJob)
    If job.JobName="j" Then
        ProgressDialogHide
        Log(job.GetString)
        'job.Release
    Else
        ProgressDialogHide
        Msgbox(job.ErrorMessage, "Ocurrió un error!")
        job.Release
    End If
End Sub

java.io.FileNotFoundException: /data/user/0/com.ferdari.defio/cache/1: open failed: ENOENT (No such file or directory)


I understand that if the server returns as response "OK", job.GetString should return the "OK", or i dunno if im understanding bad.

I think the error is the job.GetString saves a file with the response internally, but if no response it returns the bug.

I will clear that i still not programed the PHP yet, im just testing the OkHttpUtils2 so it never returns any response. or returns the Server Error.
 

OliverA

Expert
Licensed User
Longtime User
Yup, bombs out (I'm using B4J v6.01). One thing I noticed is that the site you are using redirects to noten.in.

No, I'm doing something wrong. Need to parse my error messages better.
 
Last edited:

OliverA

Expert
Licensed User
Longtime User
java.io.FileNotFoundException: /data/user/0/com.ferdari.defio/cache/1: open failed: ENOENT (No such file or directory)
I have a quick question. Do you even have a file named sometempfile.jpg in your File.DirInternalCache? Because that is what happened to me in post #8, I forgot to put a jpg in the location that I was using (File.DirApp for B4J).
 

Ferdari

Active Member
Licensed User
Longtime User
I have a quick question. Do you even have a file named sometempfile.jpg in your File.DirInternalCache? Because that is what happened to me in post #8, I forgot to put a jpg in the location that I was using (File.DirApp for B4J).
Yep i checked about 100 times, before knowing the job.GetString problem

B4X:
Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        File.Copy("ContentDir", FileName, File.DirInternalCache, "sometempfile.jpg")
       
        If File.Exists(File.DirInternalCache, "sometempfile.jpg") Then
            Log("Existe")
            defioimg.Bitmap=LoadBitmapResize(File.DirInternalCache,"sometempfile.jpg",defioimg.Width,defioimg.Height,True)
        End If
    End If
End Sub

The file was retrieved correctly and loaded on a ImageView
im on v 7.30

i told you its a BUG
 

Ferdari

Active Member
Licensed User
Longtime User
Yup, bombs out (I'm using B4J v6.01). One thing I noticed is that the site you are using redirects to noten.in.

No, I'm doing something wrong. Need to parse my error messages better.
Yep but the problem is not the server. try another server that you know will have a response. like OK or something, this also will bump the error, the POST uploads fine, but then the server will respond OK, in this case the server returns Server Error because we are not uploading to a script that handles the post information.
 

OliverA

Expert
Licensed User
Longtime User
Yep but the problem is not the server. try another server that you know will have a response. like OK or something, this also will bump the error

You may want to rewrite your JobDone to check for success. The server is currently returning a 503 error (so the server is the problem) and therefore, without checking for success (the program is the problem), GetString will bomb out (natural outcome).

B4X:
Sub JobDone(job As HttpJob)
    If job.Success Then
        If job.JobName="j" Then
            ProgressDialogHide
            Log(job.GetString)
        End If
    Else
        ProgressDialogHide
        Msgbox(job.ErrorMessage, "Ocurrió un error!")
    End If
    job.Release
End Sub
 

Ferdari

Active Member
Licensed User
Longtime User
You may want to rewrite your JobDone to check for success. The server is currently returning a 503 error (so the server is the problem) and therefore, without checking for success (the program is the problem), GetString will bomb out (natural outcome).

B4X:
Sub JobDone(job As HttpJob)
    If job.Success Then
        If job.JobName="j" Then
            ProgressDialogHide
            Log(job.GetString)
        End If
    Else
        ProgressDialogHide
        Msgbox(job.ErrorMessage, "Ocurrió un error!")
    End If
    job.Release
End Sub
It is working now, as stated in other post https://www.b4x.com/android/forum/threads/strange-multipart-request-failure.74276/page-2
the POST was failing because of the UTF8 encoding on the OkhttpUtils lib, another bug there. now job.GetString is working good and returning the Response.

@Erel can you fix the OkHttpUtils, there will be a way to disable the UTF8 ecoding on the multipart, some servers can't accept POST in UTF8.
 
Last edited:
Status
Not open for further replies.
Top