Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript file upload averaging time remaining issue
    primarykey
    data
    text
    <p>I have been working on a file upload script using uploadify that calculates the remaining time of the upload. Uploadify offers a callback called onUploadProgress, which gives me some information on the current upload.</p> <p>I have this working to an extent, but the issue is on safari. The time remaining script is not accurate, it will jump around between say, 10 and 20 minutes remaining on a large file - this is acceptable. On Safari, the deviation is huge, it will move between 0 and 300 minutes remaining, even on small uploads.</p> <p>The idea I had was to average the time remaining by adding up the timeLeft value on each progress (total), and incrementing a value by 1 (numberofpolls), so the average could be calculated by total/numberofpolls. </p> <p>The code below contains the function for CalcTime and the callback for onUploadProgress.</p> <pre><code>var total = 0; var numberofpolls = 0; var avg = 0; function CalcTime(newTime) { total += parseFloat(newTime); numberofpolls++; avg = (total / numberofpolls); return avg; } ... 'onUploadProgress' : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) { // remaining amount of bytes in upload var remaining = totalBytesTotal - totalBytesUploaded; // approx amount of time left. var timeLeft = (((remaining - (Date.now() - timeStarted) * this.queueData.averageSpeed) / this.queueData.averageSpeed) /60)/1000; var tmp_time = CalcTime(timeLeft ); if (tmp_time&lt;=1) var suffix = "Less than a minute remaining"; else var suffix = ~~(tmp_time)+ ' minute(s) remaining'; } </code></pre> <p>The problem isn't in the calculation of timeLeft - as this worked before, the issue is averaging the values of timeLeft via CalcTime. If there is a better way to stop safari doing this, or a better way to calculate it, any help would be appreciated.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload