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. incendio

    incendio Well-Known Member Licensed User

    Hi guys,

    I used RDC in my app, without HttpUtils2 library, RDC doesn't work, is it possible to make download & RDC works?

    Thanks in advance.
     
    Last edited: Oct 13, 2014
  2. Erel

    Erel Administrator Staff Member Licensed User

    Which error do you get when you use these modules with RDC?
     
  3. incendio

    incendio Well-Known Member Licensed User

    I got error message like this :
    Unfortunately myapp has closed.

    Myapp just quit. It was happen on login, which I use RDC to load user name & password from remote server.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Check the logs. You will find the full error message there.

    You can always change HttpJob and HttpUtils2Service names to HttpJob2 and HttpUtils2Service2 and then add a reference to HttpUtils2 library.

    However you will also need to update the code in HttpJob2 and HttpUtils2Service2 so the new modules are used.
     
  5. incendio

    incendio Well-Known Member Licensed User

    I renamed HttpJob and HttpUtils2Service, RDC worked fine, but there are 2 errors
    1) Downloading running but Progress bar and label that shows downloaded size was not updated
    2) After Downloading running for a while, it raised an error : "Unfortunately myapp has stopped"

    Downloading is point to dropbox. Use friend phone to test it, but this device not attached to pc, so don't know the logs.

    My tablet is attached to PC but for a strange reason, this tablet can't even connect to www.dropbox.com, thats why, tested on friend phone.

    If only running your example (without HttpUtils2 library) on phone, it was ok. I guest it was conflict with HttpUtils2 library.
     
  6. ibra939

    ibra939 Active Member Licensed User


    Erel this for saving the file or URL ?
     
  7. ibra939

    ibra939 Active Member Licensed User

    Problem attached file
     

    Attached Files:

  8. Erel

    Erel Administrator Staff Member Licensed User

    Your dd_complete code is wrong.

    It should be:
    Code:
    Sub dd_Complete(Job As HttpJob)
       
    Log("Job completed: " & Job.Success)
       
    If Job.Success Then
       
    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
     
    End IF
    Job.Release
    End Sub
     
  9. ibra939

    ibra939 Active Member Licensed User

    thanks for your help Erel ....
     
  10. ibra939

    ibra939 Active Member Licensed User

    , IsInitialized=true]: open failed: ENOENT (No such file or directory) mp3 file Link
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    You should post the full error message and the relevant code.
     
  12. ibra939

    ibra939 Active Member Licensed User

    but the size for the file 850kb .....not working donload as i test pdf file

    ** Activity (main) Pause, UserClosed = false **


    ** Activity (main) Resume **


    ** Activity (main) Create, isFirst = true **


    ** Activity (main) Resume **


    ** Service (downloadservice) Create **


    ** Service (downloadservice) Start **


    ** Service (httputils2service) Create **


    ** Service (httputils2service) Start **


    false


    java.io.FileNotFoundException: /storage/sdcard0/Android/data/B.altoki/files/[CountingStream=(MyOutputStream) anywheresoftware.b4a.randomaccessfile.CountingStreams$MyOutputStream@414aea70, Data=[EventName=dd, url=http:/moysar.com/download/molay.mp3, Target=class B.altoki.main


    , IsInitialized=false], Total=880768
    , IsInitialized=true]: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:460)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:370)
    at B.altoki.main._dd_complete(main.java:378)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:952)
    at android.os.Handler.handleCallback(Handler.java:800)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:194)


    at android.app.ActivityThread.main(ActivityThread.java:5371)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Posix.open(Native Method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
    at libcore.io.IoBridge.open(IoBridge.java:444)
    ... 16 more
    java.io.FileNotFoundException: /storage/sdcard0/Android/data/B.altoki/files/[CountingStream=(MyOutputStream) anywheresoftware.b4a.randomaccessfile.CountingStreams$MyOutputStream@414aea70, Data=[EventName=dd, url=http:/moysar.com/download/molay.mp3, Target=class B.altoki.main
    , IsInitialized=false], Total=880768
    , IsInitialized=true]: open failed: ENOENT (No such file or directory)
    ** Activity (main) Pause, UserClosed = true **
     

    Attached Files:

    Last edited: Oct 26, 2014
  13. Cableguy

    Cableguy Expert Licensed User

    aren't you missing an extra '/' here?

    ....http://moysar.com/download/molay.mp3...
     
  14. ibra939

    ibra939 Active Member Licensed User

  15. Cableguy

    Cableguy Expert Licensed User

    for the day I cannot help you much. I will try to help you with this tomorow.
    in the meanwhile, try to create a paralel simpler project just to accomplish file download... then you can start building on it...
     
  16. ibra939

    ibra939 Active Member Licensed User

    :rolleyes:o_O:eek: Playing working fine but downloading i tried to do it .............
     
  17. Cableguy

    Cableguy Expert Licensed User

    have you tried to download via browser in a pc? just to make sure the file is not download protected...
     
  18. ibra939

    ibra939 Active Member Licensed User

    browser working fine
     

    Attached Files:

  19. Erel

    Erel Administrator Staff Member Licensed User

    You haven't fixed the code like I told you. Fix it and then post your code in Sub dd_complete.
     
  20. ibra939

    ibra939 Active Member Licensed User

    my i upload other file this with your code i inserted the change file .....o_O
    https://www.mediafire.com/?9aykcnnsvl0fxv0
     
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