Android Question HttpUtil.SaveFile

cbanks

Active Member
Licensed User
Longtime User
I have some lines in my code that begin with HttpUtil.SaveFile

I'm converting to the new okHttp/HttpUtil2 etc.

How do I make that code work with the new library?
 

DonManfred

Expert
Licensed User
Longtime User
Like you did it with httputils2.

In Jobdone event you save the file

B4X:
        If Job.JobName = "DownloadImage" Then
            Dim m As Map = Job.Tag
      Dim OutStream As OutputStream
      Log("DownloadReady: "&Job.Tag)
      OutStream = File.OpenOutput(File.DirRootExternal, m.Get("filename"), False)
      File.Copy2(Job.GetInputStream,OutStream) ' save the file
      OutStream.Close
      Log(m.Get("filename")&" is written to "&File.DirRootExternal)

Note that i was using a Map inside the Job.Tag to store some infos.
But the principle you should see
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

Start the job. Wait for the JobDone event get raised and check the Job.Success inside this sub. You can not hold the mainthread.
The job will run async

B4X:
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success = False Then
        Log(Job.ErrorMessage)
    else If Job.Success Then
        end if
        Job.Release
end sub
 
Upvote 0
Top