Assuming that uploadedBytes
is changing during upload.
-> Call this script when you know that the upload starts:
var timecontroller = setInterval(function(){ timeElapsed = (new Date()) - timeStarted; // Assuming that timeStarted is a Date Object uploadSpeed = uploadedBytes / (timeElapsed/1000); // Upload speed in second // `callback` is the function that shows the time to user. // The only argument is the number of remaining seconds. callback((totalBytes - uploadedBytes) / uploadSpeed); }, 1000)
-> When the file was fully uploaded, clear interval timecontroller
:
clearInterval(timecontroller)
Pay attention that timeStarted
must be a Date object.
Tell me if its work.Thanks to @Stefano Sanfilippo - I use some of his script.