Android Tutorial Download huge files with HttpUtils2

Status
Not open for further replies.
Better to use: https://www.b4x.com/android/forum/threads/simple-progress-http-download.127214/#post-796463

The attached project includes a slightly modified version of HttpUtils2 and a new service named DownloadService. The purpose of DownloadService is to make it simple to download files of any size.

SS-2013-06-13_17.34.35.png


It is very simple to use this service.

Start a download:
B4X:
Sub btnDownload_Click
   Dim dd As DownloadData
   dd.url = link1 '<--- download link
   dd.EventName = "dd"
   dd.Target = Me
   CallSubDelayed2(DownloadService, "StartDownload", dd)
End Sub

Handle the events:
B4X:
Sub dd_Progress(Progress As Long, Total As Long)
   ProgressBar1.Progress = Progress / Total * 100
   Label1.Text = NumberFormat(Progress / 1024, 0, 0) & "KB / " & _
      NumberFormat(Total / 1024, 0, 0) & "KB"
End Sub

Sub dd_Complete(Job As HttpJob)
   Log("Job completed: " & Job.Success)
   Job.Release
End Sub

Cancel a download:
B4X:
Sub btnCancel_Click
   CallSubDelayed2(DownloadService, "CancelDownload", link1)
End Sub

DownloadService allows you to download multiple files at once and track the progress of each one of them.

The following libraries are required:
OkHttp
StringUtils
Phone (required in order to acquire a partial lock during the download)
RandomAccessFile

As this is a modified version of OkHttpUtils2 you should not reference OkHttpUtils2 library. You should instead add the three modules from the attached project. Note that the modified code is in Sub hc_ResponseSuccess.
 

Attachments

  • LargeFileDownload.zip
    11.5 KB · Views: 1,586
Last edited:

DonManfred

Expert
Licensed User
i downloaded the sample, changed the url to yours.
Out of three runs i got
LogCat connected to: 9885e6514556383552
--------- beginning of main
--------- beginning of system
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (downloadservice) Create **
** Service (downloadservice) Start **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
java.net.ProtocolException: unexpected end of stream
Job completed: false
Job completed: true
Job completed: true

but it works at least....
 

ibra939

Active Member
Licensed User
Hello,

the example works very well with small files. In my app you can download a large file (~42 Mb):

http://www.g-daehling.de/tempomaster/test.zip

i dont know why not download with me ? is the file full

It is very often several attempts to load the file completely. The criticism comes from very many users of the app. What can be the problem ?

Best regards,
Gunnar from Magdeburg in Germany
 

Tempomaster

Active Member
Licensed User
I´ve changed the url to a file on my webspace.
It has just finished the third download of a 101mb file successfully.

Note that network errors can happen due to bad internet connection, other network problems.

I think that is not the reason. Too many users of the app report the error. Downloading this file with other apps works reliably. There are other solutions in B4A ?
 

ibra939

Active Member
Licensed User
I´ve changed the url to a file on my webspace.
It has just finished the third download of a 101mb file successfully.

Note that network errors can happen due to bad internet connection, other network problems.

the file note wotking i download it show my this

Please re-upload the file i need to check it
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    315.6 KB · Views: 418

ibra939

Active Member
Licensed User
I think that is not the reason. Too many users of the app report the error. Downloading this file with other apps works reliably. There are other solutions in B4A ?


I´ve changed the url to a file on my webspace.
It has just finished the third download of a 101mb file successfully.

Note that network errors can happen due to bad internet connection, other network problems.

where the new file URL we need the file to test it ???
 

aidymp

Active Member
Licensed User
The file is ok. The screenshot shows the content of the zip file. The download routine from post #1 does not work reliably.

Maybe I can shed some light on this, I had the same problem! i wrote an app for a client in China, the app was fine running it in the UK, they said the app did not work! download kept failing, so after lots of tests it appeared that most servers seem to stall if only for a few milliseconds, this doesn't cause any problems for most programs or web browsers however this method is seems to fail instantly. I have since switched to an expensive VPS so i get this error very rarely. But it seems to have just resurfaced but only on Apple Mac's I use the same base code for my Android, PC and Mac app, all are fine, but i am getting download failures on Macs'

I did read there was a way to change the timeout, but its not supported with this method, maybe someone can advise if we can change the timeout on this routine?

Thanks

Aidy
 

Martin Larsen

Active Member
Licensed User
Would we be better off using the new resumable subs and the Wait For construction instead of using this library?
 

aidymp

Active Member
Licensed User
Is this still current? or is there a newer method?

Sorry I'm recreating old projects so may ask this on a few threads, as the forum is getting a little cluttered with old news!

Thanks

Aidy
 
Status
Not open for further replies.
Top