Android Tutorial Download huge files with HttpUtils2

Status
Not open for further replies.

cbal03

Member
Licensed User
Since your ftp client can download them and your app can't.. Possibly there is a permissions issue with your server setup. The FTP server has permission to send to client but does your app have permissions in the manner that it is connecting?
 

Kwame Twum

Active Member
Licensed User
Thanks guys... Erel , I found out the mime types on my server were only set to default file types. I manually included the ones that were causing issues (.apk, .amr, etc). Now my app downloads just fine. @cbal03 so set Full Control permissions... just in case ;) Thanks a lot.
 

Amin Ismail

Active Member
Licensed User
I modified the URL in the "LargeFileDownload" program shown in your Tutorial "Download Huge Files with HttpUtils2". Everything works fine.

Then I intentionally changed the name of download file to a non-existant file in an attempt to see what sort of error message I would get. So I get the following error message.

----------------------------------
An error has occurred in sub:
java.io.FileNotFoundException:/data/data/b4a.example/cache/1:eek:pen failed: ENOENT (No such file or directory) Continue?
----------------------------------

I tried using Try-Catch at various places in the program so I could trap this error and display a more informative message but I can't seem to trap this error.

Any suggestions on what I can do to trap it?
 

Penfound

Active Member
Licensed User
The file is downloaded to a temporary folder. You should use File.Copy2 together with Job.GetInputStream to copy the file.
I still can't find the file that has been downloaded. How do I download it and copy it to a specified folder?

Please?

Penfound
 

Erel

Administrator
Staff member
Licensed User
B4X:
Dim out As OutputStream = File.OpenOutput(...) 'target folder
File.Copy2(Job.GetInputStream, out)
out.Close
 

Bart Kerver

New Member
Licensed User
I created a (huge) file uploader that basically works fine (based on the download demo, pretty straight foreward).

In order the give feedback on the upload status (when using GSM/UTMS), I tried to create a bytes sent in some way.

Is there a way to get the amount of bytes sent (from within the httpclient object), since for the post you only pass the HttpRequest object and the file, the rest is done automatically. The CountingStream in the demo works different since that's done by the receive.

Or do I need to abandon the standard httpclient and work with the async and create own http protocol (hand-shake, error-code etc) for that?

I looked into tapping into the httpclient object using the Reflector but it seems to pretty well hidden ;)

Thanks,
Bart
 

Erel

Administrator
Staff member
Licensed User
Just pass a counting stream to HttpRequest.InitializePost.
 

Erel

Administrator
Staff member
Licensed User
There is no support for pausing and resuming. You can only abort the download.
 

Callan

Member
Licensed User
Hi Erel,
I'm tried the sample for this and I got this
error on debug.

B4X:
Parsing code.                          0.02
Compiling code.                        0.36
Compiling layouts code.                0.17
Generating R file.                      0.13
Compiling debugger engine code.        Error
javac 1.7.0_51
shell\src\b4a\example\main.java:31: error: package anywheresoftware.b4a.pc.RapidSub does not exist
        anywheresoftware.b4a.pc.RapidSub.moduleToObject.put("b4a.example.main", "b4a.example.main");
                                        ^
1 error
I haven't change any codes yet just a fresh debug. If so, what extra codes are necessary to evade this issue.
Cheers,
Callan
ps. I've got the updated version of http (v1.33)
 

Erel

Administrator
Staff member
Licensed User
Note that the latest version of Http library is 1.36 and it is included in the IDE.

Seems like something is broken in your installation. The IDE probably uses an old version of DebugRapid.jar.

Try to uninstall B4A, make sure that all the internal libraries were deleted and reinstall it.
 

Callan

Member
Licensed User
I tried it with debug legacy and it works seems to be an issue with V3.8 then....I'd also like to know how will I be able to store the file it in a folder in the ext card rather than just the root...
Here is my code
B4X:
Sub dd_Complete(Job As HttpJob)
    Log("Job completed: " & Job.Success)
    Dim o As OutputStream
    o = File.OpenOutput(File.DirDefaultExternal, "test.zip", False)
    File.Copy2(Job.GetInputStream, o)
    o.Close
    Log("Job completed: " & Job.Success)
    Job.Release
End Sub
 

Erel

Administrator
Staff member
Licensed User
RapidSub is indeed related to the rapid debugger. You are the only one who encountered this issue. It seems like you are referencing an old version of the jar.

The code above will copy it to a folder inside the sd card. Not the root. Check Log(File.DirDefaultExternal).
 

Callan

Member
Licensed User
Hey Erel,
Just a quick question is it possible to download a whole subfolder?
If not what would be the best way to do it.
Cheers
 

RickyT

New Member
Licensed User
Hi i'm getting an error while doing job complete... This is the code
B4X:
Sub dd_Complete(Job As HttpJob)
    Log("Job completed: " & Job.Success)
    Dim o As OutputStream
    o = File.OpenOutput(File.DirDefaultExternal, "test.txt", False)
    File.Copy2(Job.GetInputStream, o)
    o.Close
   Log("Directory : " & File.DirDefaultExternal)
    Log("Job completed: " & Job.Success)
    Msgbox("Download completed","Success")
    Job.Release
End Sub
And this is the error code
B4X:
java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=localhost/ComiX/30DaysOfNight/
Job completed: false
Could I please get some help with this please :)
 
Status
Not open for further replies.
Top