I need to upload a file to the server and monitor its progress. I need to get a notification about how many bytes are sent each time.
For example, in case of loading, I have:
HttpURLConnection connection = (HttpURLConnection) m_url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
while ((currentBytes = stream.read(byteBuffer)) > 0) {
totalBytes+=currentBytes;
//calculate something...
}
Now I need to do the same for the download. but if you use
OutputStreamWriter stream = new OutputStreamWriter(connection.getOutputStream());
stream.write(str);
stream.flush();
than I canβt get a progress notification, about how many bytes are sent (this looks like an automatic action).
Any suggestions?
thank
source
share