Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  138] [ 7]  / answers: 1 / hits: 8298  / 11 Years ago, thu, january 16, 2014, 12:00:00

In my jQuery file uploader I have the following available variables: uploadedBytes, totalBytes and timeStarted.



How do I caculate the time remaining for an upload using these variables? I came across a similar question that involved an uploadSpeed variable.



Can I deduce the uploadSpeed from these variables? Or am I able to calculate time remaining using only those three variables?


More From » jquery

 Answers
31

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.


[#48638] Wednesday, January 15, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jananauticat

Total Points: 1
Total Questions: 105
Total Answers: 95

Location: Azerbaijan
Member since Fri, May 12, 2023
1 Year ago
;