There is a related discussion in HttpUtils thread.
Note that HttpUtils.PostFile sends smaller files (< 1mb) by first reading the whole file to a bytes array. If you want to pass a CountingInputStream then you will need to remove this check.
Hi Erel,
Thank you for your reply.
Can you link me the post # how to discuss about progress?
I've searched all post without success.
thank you
Alessio
update:
I've found post about progress http://www.b4x.com/forum/71551-post92.html.
Unfortunately this is about download.
I woul'd like to say if is possibile to chek upload file.
If you are using HttpUtils2 then you should modify HttpJob.PostFile:
B4X:
Public Sub PostFile(Link As String, Dir As String, FileName As String)
Dim length As Int
If Dir = File.DirAssets Then
Log("Cannot send files from the assets folder.")
Return
End If
length = File.Size(Dir, FileName)
Dim In As InputStream = File.OpenInput(Dir, FileName)
cin.Initialize(In)
req.InitializePost(Link, cin, length)
CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
cin is a global variable of type CountingInputStream. You should use a timer to check cin.Count and report the progress.
If you are using HttpUtils2 then you should modify HttpJob.PostFile:
B4X:
Public Sub PostFile(Link As String, Dir As String, FileName As String)
Dim length As Int
If Dir = File.DirAssets Then
Log("Cannot send files from the assets folder.")
Return
End If
length = File.Size(Dir, FileName)
Dim In As InputStream = File.OpenInput(Dir, FileName)
cin.Initialize(In)
req.InitializePost(Link, cin, length)
CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
cin is a global variable of type CountingInputStream. You should use a timer to check cin.Count and report the progress.
erel, above solution is not working in jellybean, kitkat. cin.Count is zero initially then becomes total size of file. however upload is still in progress. does anyone have similar problem ?
yes for download it is working with above example. but when i use postfile in above example, same problem occurs. progress bar is initially zero and then becomes 100.
postfile progress is working fine in 2.2 & 2.3 android. since 4+ i am having problem. please help.
yes upload progress works for larger file. buffer was reading complete file at once for smaller files. however for large file also, at end part of upload when progress is 100% but in actual last block of buffer is still uploading.
is it possible to change buffer size or any other workaround for this. like count data sent over http rather than file input buffer read completed size.
This is indeed not an accurate way to monitor the progress as it monitors the input file progress.
You can make it more accurate. Use CountingInputStream to monitor the progress between 0 to 90%. Jump to 100% when JobDone is called.