Quantcast
Channel: How do I calculate the time remaining for my upload? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Frogmouth for How do I calculate the time remaining for my upload?

$
0
0

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.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>