Android Tutorial Download huge files with HttpUtils2

Discussion in 'Tutorials & Examples' started by Erel, Jun 13, 2013.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    No. You will need to download each files separately.

    Seems like you are missing http:// in the download link.
     
  2. Callan

    Callan Member Licensed User

    Hi Erel,
    The reason why I had asked this is because I am downloading comic books via xampp control panel pages and saving it to the users ext SD card and to download separate jpg's each time will be abit slow since comic books have about 28+ pages each. Is there a workaround for this. Maybe another class/library that you'll be able to suggest.
    Cheers,
    Callan
     
    Last edited: Jun 13, 2014
  3. DonManfred

    DonManfred Expert Licensed User

    No. But you can create a server side php-script for example

    call php-script from you app giving the desired name of folder. The phpscript can compress the files in that folder into one zip and returns the zip-file then.
    You then need to uncompress the zip to get all images which where inside zip.
     
    Mark Zraik and Callan like this.
  4. Callan

    Callan Member Licensed User

    That's abit out of my context. Thanks for the help though. I am now thinking of using Imagedownloader and have a clickevent so I could enlargen the first image and write some code for swipe gestures to move to the next image.
    Do you think it'd be possible?
     
  5. DonManfred

    DonManfred Expert Licensed User

    btw... Calling a url http://localhost will NOT call your XAMPP on your PC. Android will call a webserver ON YOUR DEVICE (it´s localhost :D)

    When you want to access your xampp on pc from your app you need to call a valid url. In this case you need to call http://w.x.y.z:p/comics/...
    Replace w.x.y.z with the Internetip of your PC and p with the port you are running apache.
    Make sure calls to this port will be forwarded to your PC (Router, "Port forwarding")
     
    shashkiranr likes this.
  6. Callan

    Callan Member Licensed User

    Great thanks for that:). Was wondering why it wasn't loading up in the app. Will get to that that right away
     
  7. Leomar_NS

    Leomar_NS Member Licensed User

    Sorry for this question, but I'm still newbie to B4A and am trying to understand through programming examples and trial and error.
    In LargeFileDownload, I can not set the Username and Password.
    The site I'm using requires. Someone could help me please?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Which type of authentication is required? If it is "basic" or digest authentication then you can edit StartDownload sub and set the job user and password fields.
     
  9. Leomar_NS

    Leomar_NS Member Licensed User

    Thank you for your response. I need basic authentication: User and password.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Are you downloading very large files? If not then you should use HttpJob directly instead of this example.
     
  11. Leomar_NS

    Leomar_NS Member Licensed User

    Thank you for your reply. I'm learning, so I'm testing the possibilities of use. Tested with large files and small files. Everything worked fine. As for authentication: I got no where to put the code. Sorry, I'm still quite muddled with so much information.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    You need to add it in DownloadService.StartDownload:
    Code:
    Public Sub StartDownload(data As DownloadData)
       
    If jobs.ContainsKey(data.url) Then
         
    Log("Ignoring duplicate request.")
         
    Return
       
    End If
       
    Dim J As HttpJob
       J.Initialize(data.url, Me)
       
    '<--- add the user and password here
       Dim tag As JobTag
       tag.Initialize
       tag.data = data
       J.tag = tag
       jobs.Put(data.url, J)
       J.Download(data.url)
       
    If timer1.Enabled = False Then StartTimer(data.Target)
    End Sub
     
  13. Leomar_NS

    Leomar_NS Member Licensed User

    Thank you for your response. Now I get it.
     
  14. deantangNYP

    deantangNYP Active Member Licensed User

    hi Erel..
    How should i modify this routine "Sub hc_ResponseSuccess" to use it for both of the following scenario. Please advise.. Thanks.

    Code:
    '1) Scenario 1 JSON
    Dim job_json As HttpJob
    job_json.Initialize(
    "JOB_Done", Me)   
    job_json.Download(URLHost & 
    "/inspections/file.json")

    '2) Scenario 2 LARGE FILE
    Dim dd As DownloadData
    dd.url = URLHost & 
    "/files/uploads/" & "file.zip"
    dd.EventName = 
    "dd"
    dd.Target = Me
    CallSubDelayed2(DownloadService, 
    "StartDownload", dd)
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    You don't need to modify this code at all.

    You should handle the complete event. If the files you are downloading are not really large then it will be simpler to use HttpUtils2 instead.
     
  16. deantangNYP

    deantangNYP Active Member Licensed User

    i encountered errors when using the codes without changes. What do you mean by "Complete Event"? i need to download both small and large files.
    How to merge the codes together to work seamlessly for small and large files?

    Code:
    Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
     
     
        
    ''This WORKS for SMALL Files like my JSON
             '*************'*************
            Response.GetAsynchronously("response"File.OpenOutput(TempFolder, TaskId, False), _
                
    True, TaskId)
             
    '*************'*************
     
        
    'This WORKS for Large Files
        ' ********** Modified code *************
        Dim cs As CountingOutputStream
        cs.Initialize(
    File.OpenOutput(TempFolder, TaskId, False))
        
    Dim j As HttpJob = TaskIdToJob.Get(TaskId)
        
    Dim jt As JobTag = j.Tag
        jt.CountingStream = cs
        jt.Total = Response.ContentLength
        
    If jt.Data.url = "" Then
            
    Log("Job cancelled before downloaded started")
            cs.Close
        
    End If
        Response.GetAsynchronously(
    "response", cs , _
            
    True, TaskId)
        
    '**************************************
    End Sub
     
    Last edited: Aug 27, 2014
  17. Erel

    Erel Administrator Staff Member Licensed User

    You shouldn't modify the original code. This code should work for both small and large files. However for small files it will be easier to work with HttpJob directly.
     
  18. deantangNYP

    deantangNYP Active Member Licensed User

    Thanks for the reply. i got error while using them in this manner:

    Code:
    '1) Scenario 1 JSONDim job_json As HttpJob
    job_json.Initialize("JOB_Done", Me)
    job_json.Download(URLHost & 
    "/inspections/file.json")

    '2) Scenario 2 LARGE FILEDim dd As DownloadData
    dd.url = URLHost & "/files/uploads/" & "file.zip"
    dd.EventName = 
    "dd"
    dd.Target = Me
    CallSubDelayed2(DownloadService, 
    "StartDownload", dd)
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Which error did you get?
     
  20. deantangNYP

    deantangNYP Active Member Licensed User

    Last edited: Aug 27, 2014
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice