Android Question Show progress of upload file

Blue.Sky

Active Member
Licensed User
Longtime User
Hi
I use PostString to upload file example below code
How can i show progressing of send file
Code: Copy
    ht.Initialize("upload",Module)
    ht.PostString(Library.WebService & "/upload_file",su.EncodeBase64(ou.ToBytesArray))
    ext = getFileExtension(sFile)
    stype = getFileType(ext)
    ht.GetRequest.SetContentType(stype)
    ht.GetRequest.SetHeader("key1",Library.LoginSession.Username)
    ht.GetRequest.SetHeader("key2",Library.LoginSession.Password)
    ht.GetRequest.SetHeader("key3",Library.phone1.GetDeviceId)
    ht.GetRequest.SetHeader("key4",Library.LoginSession.Token)
    ht.GetRequest.SetHeader("path",sParentPath)
    ht.GetRequest.SetHeader("name",Library.GetFilename(sFile))
    ht.GetRequest.SetHeader("extension",ext)

And i php i get file with below code
PHP: Copy
        $content = base64_decode(file_get_contents("php://input"));
        $len = strlen($content);
        $headers = apache_request_headers();
        
        foreach ($headers as $header => $value) {
            if ($header == "key1")
                $username = $value;
            if ($header == "key2")
                $password = $value;
            if ($header == "key3")
                $dev_id = $value;
            if ($header == "key4")
                $token = $value;
            if ($header == "extension")
                $ext = $value;
            if ($header == "name")
                $name = $value;
            if ($header == "path")
                $path = $value;
        }
 
You will need to use HttpUtils2 source code. Modify PostFile and use CountingInputStream from the RandomAccessFile:
Code: Copy
CountingStream.Initialize(in)
req.InitializePost(Link, CountingStream, Length)
CountingStream should be a global variable.

Now you can use a timer to monitor the progress by checking the value of CountintStream.Count
 
Upvote 0
You will need to use HttpUtils2 source code. Modify PostFile and use CountingInputStream from the RandomAccessFile:
Code: Copy
CountingStream.Initialize(in)
req.InitializePost(Link, CountingStream, Length)
CountingStream should be a global variable.

Now you can use a timer to monitor the progress by checking the value of CountintStream.Count
Thank you but i cannot change PostString(upload) to PostFile
Cannot i shpw progress in PostString?
 
Upvote 0
How large is the string? Unless the string is huge then the progress will not be very meaningful.
I programming app that upload any file to host.
maybe large or maybe small
 
Upvote 0
Thank you but i cannot change PostString(upload) to PostFile
Cannot i shpw progress in PostString?

you can try to use this (untested!)

Activity or starter
Code: Copy
Sub Process_Globals
    Dim cs As CountingInputStream
End Sub

httpjob.bas
Code: Copy
Public Sub PostBytes(Link As String, Data() As Byte)
    Dim in As InputStream
    in.InitializeFromBytesArray(Data,0,Data.Length)
    Main.cs.Initialize(in)
    req.InitializePost(Link, Main.cs, Data.Length)
  
    'req.InitializePost2(Link, Data)
    CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
 
Upvote 0
you can try to use this (untested!)

Activity or starter
Code: Copy
Sub Process_Globals
    Dim cs As CountingInputStream
End Sub

httpjob.bas
Code: Copy
Public Sub PostBytes(Link As String, Data() As Byte)
    Dim in As InputStream
    in.InitializeFromBytesArray(Data,0,Data.Length)
    Main.cs.Initialize(in)
    req.InitializePost(Link, Main.cs, Data.Length)
 
    'req.InitializePost2(Link, Data)
    CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
It test it and correctly worked.Thank you
 
Upvote 0
Back
Top