Android Question Problems with transferring a large number of photos to the server.

red30

Well-Known Member
Licensed User
Longtime User
I implemented it like this:
B4X:
Sub Post (Vin As String)
    Dim templist As List
    templist=File.ListFiles(File.DirInternal&Vin)
    Dim testerr="" As String
    Dim re=False As Boolean
    For i=0 To templist.Size-1
        Sleep(50)
        Dim s=templist.Get(i) As String
        If s.Contains(".jpg") Then        
            Service.StartForeground(1,CreateNotification("Photo "&i&" from "&(templist.Size-1)))
            CallSub2(Main,"PDS","Photo "&i&" from "&(templist.Size-1))

            Dim j As HttpJob
            j.Initialize("", Me)
            Dim basicAuth As String = "XXX:XXX"
            Dim su As StringUtils
            Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8")) As String
            Dim fd As MultipartFileData
            fd.Initialize
            fd.KeyName = "image"
            fd.Dir = File.DirInternal&Vin
            fd.FileName = templist.Get(i)
            j.PostMultipart("https://XXX", CreateMap("image": templist.Get(i)), Array(fd))
            j.GetRequest.SetHeader("Authorization", "Basic "&authInfo)
            Wait For (j) JobDone(j As HttpJob)
            If j.Success Then
                Log(j.GetString)
                re=False
            Else
                re=True
                Log("JobError: "&j.ErrorMessage)
                testerr=testerr&j.ErrorMessage& Chr(13) & Chr(10)
            End If
            j.Release
            If re Then
                Dim j As HttpJob
                j.Initialize("", Me)
                Dim basicAuth As String = "XXX:XXX"
                Dim su As StringUtils
                Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8")) As String
                Dim fd As MultipartFileData
                fd.Initialize
                fd.KeyName = "image"
                fd.Dir = File.DirInternal&Vin
                fd.FileName = templist.Get(i)
                j.PostMultipart("https://XXX", CreateMap("image": templist.Get(i)), Array(fd))
                j.GetRequest.SetHeader("Authorization", "Basic "&authInfo)
                Wait For (j) JobDone(j As HttpJob)
                If j.Success Then
                    Log(j.GetString)
                Else
                    Log("JobError: "&j.ErrorMessage)
                    testerr=testerr&"After re-sending, the error is still: "&j.ErrorMessage& Chr(13) & Chr(10)
                End If
                j.Release
            End If
        End If
    Next
    If testerr<>"" Then
        CallSubDelayed2(Main,"Err",testerr)
    End If
    Service.StartForeground(1,CreateNotification("All photos transferred"))
    CallSubDelayed2(Main,"Finish",Vin)
End Sub
Everything works, but from time to time I began to receive messages from users about transmission errors. For this I implemented a retransmission if the first time I received an error.
But I still get errors from time to time:
B4X:
java.net.SocketTimeoutException: timeout
java.net.UnknownHostException: Unable to resolve host "XXX": No address associated with hostname
Server Error (500)
As I understand it, "Server Error (500)" is a server error and I can't do anything about it, but errors starting with "java" are errors in the program. Why can these errors come? I can assume that this may be due to periodic Internet freezes. Perhaps my sending code is not written quite correctly. How to correctly implement sending a set of photos to the server, while taking into account that the Internet can periodically freeze?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is such a waste of time to implement such things in non-B4XPages projects. Try it and you will see.

You should expect all kinds of errors.

1. Timeout error - you can increase Job.Timeout though such errors will happen.
2. Unresolved host - usually happens when there is no internet connection
3. Server error - can happen for any reason.
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
It is such a waste of time to implement such things in non-B4XPages projects. Try it and you will see.

You should expect all kinds of errors.

1. Timeout error - you can increase Job.Timeout though such errors will happen.
2. Unresolved host - usually happens when there is no internet connection
3. Server error - can happen for any reason.
Writing this code in B4XPages will not save me from these errors.
As I understand it, there is nothing I can’t do with these errors? Can they always appear? Maybe when an error occurs, I should try to resend the photo more than once, for example 10 times ..
 
Upvote 0
Top