Android Question question relating to httputils2

devragland

Member
Licensed User
Longtime User
what am trying to do is, upload all text files in a particular directory to a php web service (am using httputils2 version 2.0.1, b4a version 2.00 (yes quite outdated).

am able to upload them but the problem is i get an error after the upload happens.

here's my code below:

B4X:
'Activity module
Sub Process_Globals

End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim job_upTxt As HttpJob
    Dim l As List
    l.Initialize
    l = ListFilesOnly(File.DirRootExternal & "/feedback_sys/")
    job_upTxt.Initialize("uploadFiles",Me)
   
For i =0 To l.Size -1
Msgbox(l.Get(i),"")
job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName="&l.Get(i)&"",File.DirRootExternal & "/feedback_sys",""&l.Get(i)&"")
 
Next

End Sub

Public Sub ListFilesOnly(Dir As String) As List
    Dim lstDir, lstRes As List
    lstRes.Initialize
   
    If File.Exists(Dir, "") Then

        lstDir = File.ListFiles(Dir)
     
        Dim FileName As String
     
        For i = 0 To lstDir.Size - 1
            FileName = lstDir.Get(i)
            If Not(File.IsDirectory(Dir, FileName)) Then
                lstRes.Add(FileName)
            End If
        Next
     
    End If
 
    Return lstRes

End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
       
        Case "uploadFiles"
                'show the downloaded image
                Msgbox("uploaded!","info")
                Log(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

i get a log error as shown:

B4X:
LogCat connected to: 20080411413fc082
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main

** Service (httputils2service) Create **


** Service (httputils2service) Start **


** Activity (main) Resume **


JobName = uploadFiles, Success = true


<200> upload succeeded


JobName = uploadFiles, Success = true


JobName = uploadFiles, Success = true


<200> upload succeeded


httpjob_getstring2 (B4A line: 105)


tr.Initialize2(File.OpenInput(HttpUtils2Service.TempFolder, taskId), Encoding)



java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/3: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:406)
    at java.io.FileInputStream.<init>(FileInputStream.java:78)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring2(httpjob.java:272)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring(httpjob.java:247)
    at anywheresoftware.b4a.samples.httputils2.main._jobdone(main.java:348)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$4.run(Common.java:879)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    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:390)
    ... 18 more
java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/3: open failed: ENOENT (No such file or directory)

all the files being read correctly and uploaded except for this error message popping up AFTER upload happens.

Any ideas? :)
 

udg

Expert
Licensed User
Longtime User
Don't know about your error, but AFAIK you should execute every next PostFile in the JobDone sub, soon after the code for success.
This way upon completion of each put job, you start the next one until no more files need to be uploaded.

udg
 
Upvote 0

devragland

Member
Licensed User
Longtime User
yes the error doesn't appear when i use:

B4X:
For i =0 To l.Size -1
job_upTxt.Initialize("uploadFiles",Me)
job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName="&l.Get(i)&"",File.DirRootExternal & "/feedback_sys",""&l.Get(i)&"")
 
Next

but only one file gets uploaded ...or in other words the same job gets executed again and again. i've attached the code.

B4X:
'Activity module
Sub Process_Globals

End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim job_upTxt As HttpJob
    Dim l As List
    l.Initialize
    l = ListFilesOnly(File.DirRootExternal & "/feedback_sys/")
    'job_upTxt.Initialize("uploadFiles",Me)

For i =0 To l.Size -1
job_upTxt.Initialize("uploadFiles",Me)
job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName="&l.Get(i)&"",File.DirRootExternal & "/feedback_sys",""&l.Get(i)&"")
 
Next

End Sub

Public Sub ListFilesOnly(Dir As String) As List
    Dim lstDir, lstRes As List
    lstRes.Initialize
   
    If File.Exists(Dir, "") Then

        lstDir = File.ListFiles(Dir)
     
        Dim FileName As String
     
        For i = 0 To lstDir.Size - 1
            FileName = lstDir.Get(i)
            If Not(File.IsDirectory(Dir, FileName)) Then
                lstRes.Add(FileName)
            End If
        Next
     
    End If
 
    Return lstRes

End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName

        Case "uploadFiles"
                'show the downloaded image
                Msgbox("uploaded!","info")
                Log(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You need to DIM each job inside your for loop. Erel already said that!

However you should create a new HttpJob for each request:
B4X:
For i =0 To l.Size -1
Dim job_upTxt As HttpJob
job_upTxt.Initialize(...)
job_upTxt.PostFile(...)
Next
 
Upvote 0

devragland

Member
Licensed User
Longtime User
i still get the error if transferring more than 3-4 files...it seems to appear on random, ive attached my source and log.

can anyone replicate this with the code attached?

any ideas?

log error
----------

B4X:
LogCat connected to: 20080411413fc082
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main




java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/4: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:406)
    at java.io.FileInputStream.<init>(FileInputStream.java:78)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring2(httpjob.java:160)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring(httpjob.java:149)
    at anywheresoftware.b4a.samples.httputils2.main._jobdone(main.java:301)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$4.run(Common.java:879)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    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:390)
    ... 18 more
java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/4: open failed: ENOENT (No such file or directory)
JobName = uploadFiles, Success = true
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true
<200> upload succeeded
<200> upload succeeded
JobName = uploadFiles, Success = true
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true


httpjob_getstring2 (java line: 160)

java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/8: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:406)
    at java.io.FileInputStream.<init>(FileInputStream.java:78)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring2(httpjob.java:160)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring(httpjob.java:149)
    at anywheresoftware.b4a.samples.httputils2.main._jobdone(main.java:301)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$4.run(Common.java:879)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:223)
    at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:136)
    at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:418)
    at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:385)
    at anywheresoftware.b4a.samples.httputils2.main._jobdone(main.java:299)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$4.run(Common.java:879)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    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:390)
    ... 29 more
java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/8: open failed: ENOENT (No such file or directory)
JobName = uploadFiles, Success = true
<200> upload succeeded
<200> upload succeeded
JobName = uploadFiles, Success = true
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true
<200> upload succeeded
httpjob_getstring2 (java line: 160)

java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/14: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:406)
    at java.io.FileInputStream.<init>(FileInputStream.java:78)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring2(httpjob.java:160)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring(httpjob.java:149)
    at anywheresoftware.b4a.samples.httputils2.main._jobdone(main.java:301)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$4.run(Common.java:879)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    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:390)
    ... 18 more
java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/14: open failed: ENOENT (No such file or directory)
JobName = uploadFiles, Success = true
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true
<200> upload succeeded
httpjob_getstring2 (java line: 160)

java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/20: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:406)
    at java.io.FileInputStream.<init>(FileInputStream.java:78)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring2(httpjob.java:160)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring(httpjob.java:149)
    at anywheresoftware.b4a.samples.httputils2.main._jobdone(main.java:301)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$4.run(Common.java:879)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    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:390)
    ... 18 more
java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/20: open failed: ENOENT (No such file or directory)
JobName = uploadFiles, Success = true
JobName = uploadFiles, Success = true
<200> upload succeeded
JobName = uploadFiles, Success = true
<200> upload succeeded
httpjob_getstring2 (java line: 160)

java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/24: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:406)
    at java.io.FileInputStream.<init>(FileInputStream.java:78)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring2(httpjob.java:160)
    at anywheresoftware.b4a.samples.httputils2.httpjob._getstring(httpjob.java:149)
    at anywheresoftware.b4a.samples.httputils2.main._jobdone(main.java:301)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$4.run(Common.java:879)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    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:390)
    ... 18 more
 

Attachments

  • source.zip
    9.8 KB · Views: 170
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You are ZIPping all files in folder File.DirRootExternal & "/feedback_sys/" to an zip-file... Why you dont wait for the Event Arc_ZipDone and then just upload the compressed file?
How big is such an resulting zip of your folder /feedback_sys???


AS i dont have your folder i´ve rewitten the code to compress the contents of my Donloadfolder....

B4X:
    Dim l As List
    l.Initialize
    l = ListFilesOnly(File.DirRootExternal & "/Download/")
    For i =0 To l.Size -1
        Log("File: "&l.Get(i))
    Next
    'job_upTxt.Initialize("uploadFiles",Me)
    Arc.AsyncZipFolder(File.DirRootExternal & "/Download/",File.DirRootExternal ,"feedback_"&DateTime.Date(DateTime.now)&".zip","Arc")

and then use the events...

B4X:
Sub Arc_ZipDone(CompletedWithoutError As Boolean, NbOfFiles As Int)

    Log("Arc_ZipDone("&CompletedWithoutError&", "&NbOfFiles&")")
    Dim job_upTxt As HttpJob
    job_upTxt.Initialize("uploadFiles",Me)
    job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName=feedback_"&DateTime.Date(DateTime.now)&".zip",File.DirRootExternal,"feedback_"&DateTime.Date(DateTime.now)&".zip")
End Sub
Sub Arc_ZipProgression(Count As Int, FileName As String)
    Log("Arc_ZipProgression("&Count&", "&FileName&")") 
End Sub

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
File: AmazonApps-release.apk
File: de_androidpit_appcenter-v1765-KL54S8R8.apk
Arc_ZipProgression(1, Download/AmazonApps-release.apk)
Arc_ZipProgression(2, Download/de_androidpit_appcenter-v1765-KL54S8R8.apk)
Arc_ZipDone(true, 2)
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
JobName = uploadFiles, Success = false
Error: org.apache.http.conn.ConnectTimeoutException: Connect to /172.17.1.74:8080 timed out
** Activity (main) Pause, UserClosed = true **

It should work if i can reach the host... 172.17.1.74 seems to be not an online host for me here....
 
Last edited:
Upvote 0

devragland

Member
Licensed User
Longtime User
@DonManfred i tried that too.

B4X:
Dim now As Long,cur_dt_fmt As String
DateTime.DateFormat = "dd-MM-yyyy"
cur_dt_fmt=DateTime.Date(DateTime.now)

Arc.AsyncZipFolder(File.DirRootExternal & "/feedback_sys",File.DirRootExternal & "/fb_out","feedback_"&cur_dt_fmt&".zip","Arc")

Dim job_upTxt As HttpJob
job_upTxt.Initialize("uploadFiles",Me)
job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName=feedback_"&cur_dt_fmt&".zip",File.DirRootExternal & "/fb_out","feedback_"&cur_dt_fmt&".zip")

my php codes is:

PHP:
<?php
$flName = $_REQUEST['fileName'];

$file_path = "uploads/";
//$file_path="uploads/".$flName;
$file_path="uploads/".$flName;
$url = 'php://input';
$tmpName = file_get_contents($url);

$info = pathinfo($file_path);
if ($info["extension"] == "zip") {

if (file_put_contents($file_path, file_get_contents("php://input", "r"))) {
echo "<200> upload succeeded";
    } else {
    echo "<404> upload failed";
}
}

?>

the problem is, the zip file becomes corrupt when transferring to the upload folder sometimes. which is an anomaly. filesize is '0' sometimes.
(the zip file does get created but corrupt). sometimes it transfers fine.

the LAMP server is hosted locally by the way.

EDIT: filesize is less that 1MB. (will there be an issue for larger file sizes using httputils2?)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
hmm..maybe am sending the file before compression completes? any ideas?

Sure you start uploading without compression completes... You have to wait for the arc_ZipDone event before uploading anything if you just want the zip to upload....

Please note that you are using an ASYNC-function of that lib. It will fire one or more events till it´s finishes...

Please also note that you DON´T need the httputilsservice.bas and httputils.bas. You just need the httputils2-library checked in the lib-tab... See here.

that´s my Button click sub

B4X:
Sub Button1_Click
'ProgressBar1.Initialize("prg")
    DateTime.DateFormat = "dd-MM-yyyy"
    Dim now As Long

    Dim l As List
    l.Initialize
    l = ListFilesOnly(File.DirRootExternal & "/Download/")
    For i =0 To l.Size -1
        Log("File: "&l.Get(i))
    Next
    'job_upTxt.Initialize("uploadFiles",Me)
    Arc.AsyncZipFolder(File.DirRootExternal & "/Download/",File.DirRootExternal ,"feedback_"&DateTime.Date(DateTime.now)&".zip","Arc")
    ' Now wait for the zip finishes
End Sub
Sub Arc_ZipDone(CompletedWithoutError As Boolean, NbOfFiles As Int)

    Log("Arc_ZipDone("&CompletedWithoutError&", "&NbOfFiles&")")
    Dim job_upTxt As HttpJob
    job_upTxt.Initialize("uploadFiles",Me)
    job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName=feedback_"&DateTime.Date(DateTime.now)&".zip",File.DirRootExternal,"feedback_"&DateTime.Date(DateTime.now)&".zip")
End Sub
Sub Arc_ZipProgression(Count As Int, FileName As String)
    Log("Arc_ZipProgression("&Count&", "&FileName&")")
End Sub
 
Last edited:
Upvote 0

devragland

Member
Licensed User
Longtime User
@DonManfred thanks! it works great but out of 1 in 10 times i get that error now..it seems to be random. but the file is uploaded successfully all times!.

the exact error log i get is:

B4X:
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:390)
    ... 18 more
java.io.FileNotFoundException: /data/data/anywheresoftware.b4a.samples.httputils2/cache/34: open failed: ENOENT (No such file or directory)

it displays this error in a msgbox, if atleast there is a way to handle this exception and suppress it that would be fine.

i will also explore your solution @DonManfred , am not sure if its compatible with b4a 2.00, has anyone tested it on this version?

also another anomaly i noticed is that the 'jobdone' sub is executed twice for one postfile.
 
Upvote 0

devragland

Member
Licensed User
Longtime User
well, am just stopping the service when a successful callback occurs:

B4X:
Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
    StopService("HttpUtils2Service")
        Select Job.JobName

        Case "uploadFiles"
   
                'show the downloaded image
                Msgbox("uploaded!","info")
   
   
   
       
        '        Log(Job.GetString)
               
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release   
End Sub

it works because am just uploading a single file as a zip, its not optimal it works. have to test further and yes, have to update b4a! :)
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi devragland,

since you're still experimenting, did you try my suggestion from post #2?
I'm curious to know if it solves the "missing" file error when you upload many files.
Please find here a very brief skeleton example code based on your original code from post#1

B4X:
Sub Activity_Create(FirstTime AsBoolean)
  Dim l As List
  l.Initialize
  l = ListFilesOnly(File.DirRootExternal & "/feedback_sys/")
  if l.Size > 0 then
    Dim job_upTxt As HttpJob
    job_upTxt.Initialize("uploadFiles",Me)
    Msgbox(l.Get(0),"")
    job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName="&l.Get(0)&"",File.DirRootExternal & "/feedback_sys",""&l.Get(0)&"")
  Else
     'no files to upload
  End If
End Sub

Sub JobDone (Job As HttpJob)
  Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
  If Job.Success = True Then
    Select Job.JobName
      Case "uploadFiles"
        'show the downloaded image
        Msgbox("uploaded!","info")
        ' Log(Job.GetString)
        l.RemoveAt(0)  'remove first item, the one just uploaded ok
        'check for any further items and upload what now is first in your list
        if l.Size > 0 then
          Dim job_upTxt As HttpJob
          job_upTxt.Initialize("uploadFiles",Me)
          job_upTxt.PostFile("http://172.17.1.74:8080/uls/index.php?fileName="&l.Get(0)&"",File.DirRootExternal & "/feedback_sys",""&l.Get(0)&"")
        end if
    End Select
  Else
    Log("Error: " & Job.ErrorMessage)
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
  End If
  Job.Release
End Sub

I didn't test the above code; read it just as a suggestion for a different way to approach your problem.

udg
 
Upvote 0

devragland

Member
Licensed User
Longtime User
@udg i havent tested that out yet, i probably will next week as for now, am a bit pressed for time but thanks for the effort udg. the above solution i posted where stopping the service after an upload works (for a single file) .as of now am just zipping all files and sending a single zip so it works fine for me.

thank you DonManfred and Erel for you support too. actually we did buy an enterprise license in another department and i just got the package so planning to use the latest and greatest of b4a!
 
Upvote 0
Top