Android Question HTTPJOB troubles

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,
I try to download a file,
I think I post my troubles in the code.

B4X:
     fname=Main.photonumber & ".zip"
     Dim s As String
     s=Main.hostname & "uploads/" & fname
     DoEvents
     Dim jobdnld As HttpJob     
     jobdnld.Initialize ("dnld",Me)
     ' the file s exists - I checked
     jobdnld.Download (s)
     jobdnld.GetRequest.timeout=6000000


Sub JobDone (job As HttpJob)
   Dim t As String
   If job.Success = True Then
  Select job.JobName
       
       Case "dnld":
         t=job.GetString
         ' t is a very long string, completely illegible, looks like random
         log (t)
         ' system says that t is too big
         If File.Exists (Main.outdir, fname) = False Then
           Basis.debuginfo ("exiting",False)
           Return
           ' the program comes to here
         End If
 

DonManfred

Expert
Licensed User
Longtime User
If you expect to get an image then it it not a good idea to use GetString or even log().
Write the data to disc as jpg...

Edit: i just saw you are downloading a zip... Then you shuld save the content to disc giving a .zip extension ;-)
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
fname=Main.photonumber & ".zip"
     Dim s As String
     s=Main.hostname & "uploads/" & fname
     'DoEvents
     Dim jobdnld As HttpJob    
     jobdnld.Initialize ("dnld",Me)
    jobdnld.tag = fname
     ' the file s exists - I checked
     jobdnld.Download (s)
     jobdnld.GetRequest.timeout=6000000
and then in jbdone
B4X:
Sub JobDone (job As HttpJob)
   Dim t As String
   If job.Success = True Then
  Select job.JobName
      
       Case "dnld":
         't=job.GetString
         ' t is a very long string, completely illegible, looks like random
         'log (t)
         ' system says that t is too big
      Dim OutStream As OutputStream
      Log("DownloadReady: "&job.Tag)
      OutStream = File.OpenOutput(File.DirRootExternal, job.Tag, False) ' Job.Tag is read to set the Original Filename we specify earlier in the creation of the Job
            File.Copy2(job.GetInputStream,OutStream) ' save the file
        OutStream.Close
        Log(job.Tag&" written to "&File.DirRootExternal) ' Write the Originalname to the log to see what happens ;-)
         If File.Exists (Main.outdir, fname) = False Then
           Basis.debuginfo ("exiting",False)
           Return
           ' the program comes to here
         End If
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Thank you!

I did it this way, only asked BEFORE if the file exists. Idiotic.

But it worked at some time, absolutely no idea why. This happens when you test with yourself instead of others :)

Thanks, your help is much appreciated as always. Have a great New Year.
 
Upvote 0
Top