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.
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)
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.
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.
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.
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).
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
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.
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
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