Android Tutorial Download huge files with HttpUtils2

Status
Not open for further replies.

Giacomo

Active Member
Licensed User
Longtime User
I try to compile this app " LargeFileDownload" but I always make the same mistake.
I already tried to reinstall B4A without result. ( and erase all Lib)


 

Alisson

Active Member
Licensed User
I have one url with file. Exemple:
http://www.site.com/rss/
How get the file in url and save to scard/

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Private link1 As String = "http://www.site.com/rss/"
End Sub

Sub Globals
    Dim ProgressBar1 As ProgressBar
    Dim Label1 As Label
    Dim btnDownload As Button
    Dim btnCancel As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub btnDownload_Click
    Dim dd As DownloadData
    dd.url = link1
    dd.EventName = "dd"
    dd.Target = Me
    CallSubDelayed2(DownloadService, "StartDownload", dd)
End Sub

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)
    Dim o As OutputStream
    o = File.OpenOutput(File.DirDefaultExternal, "file.xml", True)
    'File.Copy(File.DirRootExternal & "/Android","photo1.jpg",File.DirRootExternal & "","photo.jpg")
    File.Copy2(Job.GetInputStream, o)
    o.Close
    Job.Release
End Sub

Sub btnCancel_Click
    CallSubDelayed2(DownloadService, "CancelDownload", link1)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Thanks
 

Alisson

Active Member
Licensed User
Solvetion:

B4X:
Log("Job completed: " & Job.Success)
     Job.Download("http://www.site.com/rss/")
           Dim out As  OutputStream
          out = File.OpenOutput(File.DirRootExternal,"file.xml",False)
           File.Copy2(Job.GetInputStream,out)
           out.Close
    Job.Release

Thanks
 

Alisson

Active Member
Licensed User
I change the code to:


B4X:
Dim job3 As HttpJob
        job3.Initialize("Job3", Me)
   job3.Download(link1)   
    End If
  
End Sub
Sub JobDone (Job As HttpJob)
   If Job.Success = True Then
       Job.Download(link1)
           Dim out As  OutputStream
          out = File.OpenOutput(File.DirRootExternal,"folder/"&s&".xml",False)
           File.Copy2(Job.GetInputStream,out)
           out.Close
   End If
   Job.Release
End Sub

Is correct ?
 

DonManfred

Expert
Licensed User
Longtime User
Is correct ?
no. Sorry, i did not see your error before

1. The download Job start

B4X:
   Dim job3 As HttpJob
   job3.Initialize("Job3", Me)
   job3.Tag = s ' to be used in jobdone. Place here the number you want to have the resulting xml named with
   job3.Download(link1)

B4X:
Sub JobDone (Job As HttpJob)
   If Job.Success = True Then
      if job.jobname = "Job3" then
         Dim out As  OutputStream
         out = File.OpenOutput(File.DirRootExternal,"folder/"&job.tag&".xml",False)
         File.Copy2(Job.GetInputStream,out)
         out.Close
      end if
   End If
   Job.Release
End Sub
 

jazzzzzzz

Active Member
Licensed User
Longtime User
I have okhttputilis2 linked in my project,will that conflicts to this lib? If yes how can I get download progress?
 

jazzzzzzz

Active Member
Licensed User
Longtime User
Ok I will try..

Am using imagedownloder class for downloading now and is it possible to add this download progress there also?
 

Tempomaster

Active Member
Licensed User
Longtime 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

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
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…