swfupload 获取计时器剩余时间

发布于 2024-09-12 06:20:36 字数 37 浏览 1 评论 0原文

是否有可能获得使用 swfupload 上传文件的剩余时间?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿! 2024-09-19 06:20:36

您当然可以估计剩余时间,但据我所知,这不是 SWFUpload 的内置功能。这就是我所做的:

在文件的 uploadStart() 处理程序中,记录上传的开始时间并将其存储在某处。

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

然后,在同一文件的 uploadProgress() 处理程序中:

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

效果很好!

我希望这有帮助。

编辑,添加百分比测试> 0

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

苍暮颜 2024-09-19 06:20:36

不会,因为由于速度波动,通过正常互联网连接上传任何内容所需的时间永远无法提前得知。另一方面,swfupload 提供了一个进度处理程序来报告上传的百分比,因此您可以使用它来显示进度计数器/栏,或者根据已花费的时间猜测剩余时间,并希望它有点准确。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文