Android Tutorial Download huge files with HttpUtils2

Status
Not open for further replies.

incendio

Well-Known Member
Licensed User
As this is a modified version of HttpUtils2 you should not reference HttpUtils2 library. You should instead add the three modules from the attached project.
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:

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.
 

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.
 

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.
 

Erel

Administrator
Staff member
Licensed User
Your dd_complete code is wrong.

It should be:
B4X:
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
 

ibra939

Active Member
Licensed User
Your dd_complete code is wrong.

It should be:
B4X:
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
thanks for your help Erel ....
 

Erel

Administrator
Staff member
Licensed User
You should post the full error message and the relevant code.
 

ibra939

Active Member
Licensed User
, IsInitialized=true]: open failed: ENOENT (No such file or directory) mp3 file Link
You should post the full error message and the relevant code.
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 **
 

Attachments

Last edited:

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

ibra939

Active Member
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...
:rolleyes:o_O:eek: Playing working fine but downloading i tried to do it .............
 

Cableguy

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

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.
 
Status
Not open for further replies.
Top