Android Question Download problem

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

sometimes it works, sometimes not. I download a file with about 1 mb. Sometimes the download works, sometimes the file size is only 2 bytes, sometimes the file does not even exist.

What am I doing wrong?

Thank you.

B4X:
Sub Globals
    Dim jobdnld As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Basis.FreezeOrientation
    jobdnld.Initialize ("dnld",Me)
    s=Main.hostname & "uploads/" & fname
    DoEvents
    jobdnld.Download (s)
    DoEvents
End Sub



Sub JobDone (job As HttpJob)
    Dim t As String
    If job.Success = True Then
        Select job.JobName
            Case "dnld":
                Dim out As OutputStream = File.OpenOutput(Main.outdir, fname, False)
               File.Copy2(job.GetInputStream, out)
               out.Close '<------ very important
                Log (File.Size (Main.outdir,fname))
                DoEvents
        End Select
    Else
        Msgbox (job.ErrorMessage,fname)
        Dim s As String
        s=job.JobName & " " & job.ErrorMessage & " " & fname
        Main.prot.Add ("Download " & s)
        Activity.Finish
    End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
What am I doing wrong?
You are reusing the same httpjob everytime. FAULT

B4X:
Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Basis.FreezeOrientation
    Dim jobdnld As HttpJob
    jobdnld.Initialize ("dnld",Me)
    jobdnld.Download (Main.hostname & "uploads/" & fname)
End Sub
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Yes, thank you. But even then it should have worked the first time after start. I changed the code - no success.
 
Upvote 0
Top