tags:

views:

13

answers:

2

Hello,

is it any possible to get time left for uploading files using swfupload?

A: 

No, because the time taken to upload anything over a normal Internet connection can never be known in advance due to speed fluctuations. On the other hand swfupload provides a progress handler to report the percentage uploaded so you can either use that to display a progress counter/bar or guesstimate the time remaining based on the time already spent and hope it's somewhat accurate.

SpliFF
A: 

You can most certainly estimate the time remaining, but this isn't a feature built-in to SWFUpload to my knowledge. Here's what I do:

In your uploadStart() handler for your file, record the start time of the upload and store in somewhere.

var startTime = +new Date(); // the current date time in UTC * 1000 milliseconds

Then, in your uploadProgress() handler for the same file:

var percentage = bytesLoaded/file.size,
    timeDiff = +new Date() - startTime,
    status = (percentage > 0 ? Math.round(timeDiff / percentage / 1000 * (1 - percentage)) + " seconds remaining." : "Uploading...");

Works well!

I hope this is helpful.

EDIT, added test for percentage > 0

mkoistinen