You need to modify HttpJob.PostMultipart.
1. Add a global CountingInputStream variable to HttpJob.
2. Remove the call to PostBytes and instead send the request with this code:
B4X:
Dim in As InputStream
Dim data() As Byte = stream.ToBytesArray
in.InitializeFromBytesArray(data, 0, data.Length)
cin.Initialize(in) 'global CountingInputStream
req.InitializePost(Link, cin, data.Length)
You can now track the progress with a timer by checking Job.cin.Count.
You need to modify HttpJob.PostMultipart.
1. Add a global CountingInputStream variable to HttpJob.
2. Remove the call to PostBytes and instead send the request with this code:
B4X:
Dim in As InputStream
Dim data() As Byte = stream.ToBytesArray
in.InitializeFromBytesArray(data, 0, data.Length)
cin.Initialize(in) 'global CountingInputStream
req.InitializePost(Link, cin, data.Length)
You can now track the progress with a timer by checking Job.cin.Count.
You need to modify HttpJob.PostMultipart.
1. Add a global CountingInputStream variable to HttpJob.
2. Remove the call to PostBytes and instead send the request with this code:
B4X:
Dim in As InputStream
Dim data() As Byte = stream.ToBytesArray
in.InitializeFromBytesArray(data, 0, data.Length)
cin.Initialize(in) 'global CountingInputStream
req.InitializePost(Link, cin, data.Length)
You can now track the progress with a timer by checking Job.cin.Count.
Hi @Erel . What is "cin" ... where is its declaration ?
I added this as follows but really didn't find the "cin" type or declaration...
B4X:
Sub Class_Globals
Public JobName As String
Public Success As Boolean
Public Username, Password As String
Public ErrorMessage As String
Private target As Object
Public CountInputStream As Int
...
as the call req.InitializePost(Link, Cin, data.Length) requires an InputStream object but the InputSteran doesn't have Initialize method... It seems to be a stupid error but I really didn't find the correct type for Cin ... please help!
Thanks for fast answering!
I added the reference... but still getting Unknown Member: initialize when adding Cin.Initialize(in) . Notice that Cin declaration is:
Public Cin As InputStream
I noticed also that if Cin is InputStream, then the correct call is InitializeFromBytesArray ... what means that Cin type shouldn't be InputStream... but, what is the correct Cin data type then???
You need to modify HttpJob.PostMultipart.
1. Add a global CountingInputStream variable to HttpJob.
2. Remove the call to PostBytes and instead send the request with this code:
B4X:
Dim in As InputStream
Dim data() As Byte = stream.ToBytesArray
in.InitializeFromBytesArray(data, 0, data.Length)
cin.Initialize(in) 'global CountingInputStream
req.InitializePost(Link, cin, data.Length)
You can now track the progress with a timer by checking Job.cin.Count.
Hi @DonManfred ... Thanks! You are my help from an eternal stupid loop... I knew that was simple !!! I tried to find the CountInputStream object BEFORE adding RandomAccessFileLibrary... and didn't tried again after!!! I really didn't notice that this object was dependent of this library.
Sometimes when we are programming we need an external help to see what we can't, maybe due the proximity (or caffeine excess, who knows!) - thanks again! You saved my day!
Ok... not yet
The code with PostBytes works fine (server receives file, JobDone event is raised). The code changed doesn't raise the JobDone event and the file is not uploaded to server. Any suggestion?
B4X:
b = s.Replace(CRLF, eol).GetBytes("UTF8")
stream.WriteBytes(b, 0, b.Length)
'PostBytes(Link, stream.ToBytesArray)
Dim in As InputStream
Dim data() As Byte = stream.ToBytesArray
in.InitializeFromBytesArray(data, 0, data.Length)
Cin.Initialize(in) 'global CountingInputStream
req.InitializePost(Link, Cin, data.Length)
req.SetContentType("multipart/form-data; boundary=" & boundary)
req.SetContentEncoding("UTF8")
Any suggestion? PostBytes -> works ... InitializePost -> doesn't work... Hi @Erel , could help us here ? The possibility to use this implementation could maintain the same structure of simple job.postmultipart / jobdone ...
Hi @DonManfred ... Thanks! You are my help from an eternal stupid loop... I knew that was simple !!! I tried to find the CountInputStream object BEFORE adding RandomAccessFileLibrary... and didn't tried again after!!! I really didn't notice that this object was dependent of this library.
Sometimes when we are programming we need an external help to see what we can't, maybe due the proximity (or caffeine excess, who knows!) - thanks again! You saved my day!
Hi @DonManfred ... I added a network spy at server side... the request using req.InitializePost(Link, Cin, data.Length) (HttpRequest) doesn't arrive at server... and there is no any message in Android also..
Finally, I discovered what happened. It was again a stupid detail, as I suspected. Not #ONLY# remove the call to PostBytes... It's needed to add at the end of new code the SubmitJob Call, of course ( )... if you do not call the routine, the post is prepared but will not be executed...
Then, the code in MultiPartPost routine is:
B4X:
'PostBytes(Link, stream.ToBytesArray)
Dim in As InputStream
Dim data() As Byte = stream.ToBytesArray
in.InitializeFromBytesArray(data, 0, data.Length)
Cin.Initialize(in) 'global CountingInputStream
req.InitializePost(Link, Cin, data.Length)
Log("length -> " & data.Length)
req.SetContentType("multipart/form-data; boundary=" & boundary)
req.SetContentEncoding("UTF8")
CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
I hope that this experience could be useful to somebody...