You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a code like the following, the issue is that the percentage is (almost) always 100 during the upload. I tried to make a workaround, without success. It's crucial to show the correct percentage when the upload can requires minutes or tens of minutes, otherwise the user suppose that the app is blocked.
try {
MultipartRequest request = new MultipartRequest();
request.setUrl(Server.getServerURL() + api);
long streamLength = FileSystemStorage.getInstance().getLength(filePath);
request.addData("file", filePath, "application/octet-stream");
request.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
public void actionPerformed(NetworkEvent evt) {
String response = new String(evt.getConnectionRequest().getResponseData());
Log.p("The file " + filePath + " is successfully uploaded to the cloud\n\n The response is: " + response, Log.DEBUG);
}
});
Progress progress = new Progress("Server-Uploading", request, true);
progress.setAutoShow(true);
progress.setDisposeOnCompletion(true);
NetworkManager.getInstance().addToQueue(request);
// addProgressListener added to debug, see the comment below
NetworkManager.getInstance().addProgressListener(new ActionListener<NetworkEvent>() {
@Override
public void actionPerformed(NetworkEvent evt) {
if (evt.getConnectionRequest() == request) {
Log.p("Sent data: " + evt.getSentReceived());
Log.p("Percentage: " + evt.getSentReceived() * 100 / streamLength);
}
}
});
} catch (IOException ex) {
Log.p("ServerProfile.uploadAvatar ERROR", Log.ERROR);
Log.e(ex);
}
About the NetworkManager.getInstance().addProgressListener, I added it only to debug why the shown percentage is 100 during the upload. For an upload of some megabytes that requires at least ten seconds, it logs as following. According to the log, all the file is uploaded in 18,655-18,522=0,133 seconds, but it's not true, it requires a lot more time! So, I suppose that the cause of this issue is that the file is buffered is some way and the progress listener (used by Progess) is misled.
I have a code like the following, the issue is that the percentage is (almost) always 100 during the upload. I tried to make a workaround, without success. It's crucial to show the correct percentage when the upload can requires minutes or tens of minutes, otherwise the user suppose that the app is blocked.
About the
NetworkManager.getInstance().addProgressListener
, I added it only to debug why the shown percentage is 100 during the upload. For an upload of some megabytes that requires at least ten seconds, it logs as following. According to the log, all the file is uploaded in 18,655-18,522=0,133 seconds, but it's not true, it requires a lot more time! So, I suppose that the cause of this issue is that the file is buffered is some way and the progress listener (used byProgess
) is misled.The text was updated successfully, but these errors were encountered: