Download Progress Feature for HTTPUtils when downloading file

serkanpolat

Member
Licensed User
Longtime User
hi Friends,
i implemented download progress status for httputils module..
it shows download progress for any kind of file..
also i added SaveFile function to directly save to any folder..

here is how you use it:


B4X:
Sub Process_Globals
   Type ProgressStatus(Downloaded As Long,Total As Long)
   Dim url as string
End Sub

Sub Activity_Create(FirstTime As Boolean)
   initHttp
   url="http://www.yourserver.com/myfile.MP3"
   HttpUtils.Download("downloadFile",url)
End Sub

Sub initHttp
    HttpUtils.CallbackActivity = "Main"
    HttpUtils.CallbackJobDoneSub = "JobDone"
    HttpUtils.CallbackUrlDoneSub = "UrlDone"
    HttpUtils.CallbackProgressSub="ProgressHTTP"
End Sub

Sub ProgressHTTP(tmp As ProgressStatus)
   Label1.Text=tmp.Downloaded & "/" & tmp.Total
   ProgressBar1.progress=Round((tmp.downloaded*100)/tmp.total)
End Sub

Sub JobDone (Job As String)
   Select Job
      Case "downloadFile"
      If HttpUtils.IsSuccess(url) Then
         HttpUtils.SaveFile(url,"/sdcard/","myfile.mp3")
      End If
   End Select
   HttpUtils.Complete = False   
End Sub
 

Attachments

  • httputilsWithProgressBar.zip
    2.7 KB · Views: 1,455

psdos

Active Member
Licensed User
Longtime User
One question, if file is copying is possible stop download?

I probe with StopService(HttpUtilsService) but download is in second plane.

Thanks.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Can anyone help me with this error.
I'm testing download progress with little test file but always at the end I got error.
Everything download fine but at the end of download I got error :confused:

I don't know what exactly I'm missing so if anyone can help me to correct this.

Error is this:
error.png


The project is in attachment in this post
 

Attachments

  • Progress_Download.zip
    9.6 KB · Views: 574
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
CallbackProgressSub compile error

I have add the HttpUtils & HttpUtilsService modules to my app. Code fragment from app:
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.CallbackProgressSub="ProgressHTTP"

I get on compiling:
Compiling code. Error
Error compiling program.
Error description: Unknown member: callbackprogresssub
Occurred on line: 32
HttpUtils.CallbackProgressSub="ProgressHTTP"
Word: callbackprogresssub

I have looked in the HttpUtils module and there is a Dim statement for CallbackJobDoneSub but not one for CallbackProgressSub.

What am I missing?
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
In HttpUtils.bas look if it is dimmed.

B4X:
Dim CallbackActivity As String 'Name of Activity that handles the callbacks.
   Dim CallbackJobDoneSub As String 'Name of the JobDone callback sub.
   Dim CallbackUrlDoneSub As String 'Name of the UrlDone callback sub.
   Dim CallbackProgressSub As String 'download progress of file

You can download my example here and look it: It under Post #7
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
I see the problem. The version in the start of the thread for the httputils module which is stated by Erel to be the latest version (i.e. 1.04) is different to that in this thread. I used Erel's version because it is stated by him to be the latest. This latest version does not contain the Dim statement for 'ProgressSub'. It causes confusion when people use old/changed versions of a module written by Erel. The thread for the httputils module can be found at:
http://www.b4x.com/forum/basic4android-getting-started-tutorials/9176-httputils-android-web-services-now-simple.html#post50919

Now I don't know whether to use the httputils module supplied in the http Progress zip file (even though it may have faults fixed by Erel) or whether to add the required Dim statement to Erel's latest version. Please advise, Erel.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Versions

Erel, you haven't answered my question about which version of HttpUtils module to use. To me, it's not a good idea for 'posters' to change modules that you have written without you subsequently incorporating their worthwhile code into the modules. Otherwise it may be difficult to work out how to incorporate their worthwhile code into your improved modules. This is particularly relevant when you recommend a change to a new version of a module such as from HttpUtils to HttpUtils. It seems to me that the Download Progress Bar is a very worthwhile feature to have when downloading files.
 
Upvote 0

sally3599

Member
Licensed User
Longtime User
add Sub UrlDone(Url As String) error

I add the Sub UrlDone
B4X:
Sub UrlDone(url As String)

End Sub


it displays the error:
B4X:
Compiling code.                         Error
Error parsing program.
Error description: Parameter name cannot hide global variable name.
Occurred on line: 27
Sub UrlDone(Url As String)
 
Upvote 0
Top