B4J Question Download a file with progressbar

ThRuST

Well-Known Member
Licensed User
Longtime User
I want to download a file using OkHttpUtils2 and display a progressbar while downloading.

And once the download is complete save the file to the harddrive.

How would you do this?
 

ThRuST

Well-Known Member
Licensed User
Longtime User
@xulihang That post is more than 6 years old. DownloadService is depricated and no longer compatible with the latest jOkHttpUtils2 standard. It causes a conflict.

Here's a code I started. Someone can modify it to meet the new requirements with a download que.

Requires Library:
jOKHttpUtils2 v2.80+

Process Globals
B4X:
Private DownloadFileDrive As String = "d:\"
    Private DownloadfileURL = "https://www.WebpageURLhere/Filename.zip"
    Private SaveDownloadedFileAS As String = "DownloadedFile.zip"

AppStart
DownloadFile

Initialization
B4X:
' File Download
Sub DownloadFile

    ' Declare Download Variable
    Public TransferJob As HttpJob
    ' Initialize Download
    TransferJob.Initialize("", Me)
    ' Download Link
    TransferJob.Download(DownloadfileURL)
    ' Display message in Log
    Log("Download started...")

End Sub

' File Download Completed
Private Sub JobDone (TransferJob As HttpJob)
 
    ' Transfer Successful
    If TransferJob.Success Then
   
        ' Save Downloaded File To Harddrive
        Dim out As OutputStream = File.OpenOutput(DownloadFileDrive, SaveDownloadedFileAS, False)
        File.Copy2(TransferJob.GetInputStream, out)
        out.Close
   
            ' Display message in Log
            Log("Download complete")
    Else
            ' Display message in Log
            Log("Error: " & TransferJob.ErrorMessage)
    End If
   
    ' Close File Transfer
    TransferJob.Release
 
End Sub
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
and can be safely used

How can the older service modules for the progress bar and the latest OkHttpUtils2 library be added at the same time? It generated an error message saying the library is allready added. Thereby my post. Please provide a working example that we all can follow.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
A source code example would be nice that displays options to download any of the latest B4X products and displays the current available version. Downloaded with a progressbar of course :)
 
Upvote 0
Top