简体   繁体   English

HTML5文件上载进度 - 仅限客户端

[英]HTML5 File Upload Progress - Client Side Only

I have noticed that the new XMLHttpRequest object supports an 'onprogress' event in firefox. 我注意到新的XMLHttpRequest对象支持firefox中的'onprogress'事件。 Is it possible to utilize part of the new HTML5 File api's to get an upload progress bar without any server-side modifications required? 是否可以利用部分新的HTML5文件API来获取上传进度条而无需进行任何服务器端修改?

I believe in principle yes, though I haven't tried it out yet. 我原则上相信是的,尽管我还没有尝试过。

What's going to be a problem is that XMLHttpRequest#send() takes a Unicode string and encodes it as UTF-8. 会出现问题的是XMLHttpRequest#send()接受Unicode字符串并将其编码为UTF-8。 It doesn't give you the ability to send pure binary, and most binary files like images are not going to happen to be valid UTF-8 sequences. 它不能让你发送纯二进制文件,大多数像文件这样的二进制文件也不会是有效的UTF-8序列。

So probably you'd be using what the FileAPI spec calls a “binary string” (bytes treated as ISO-8859-1, so each charCodeAt corresponds to a byte), recoded to UTF-8. 所以你可能正在使用FileAPI规范称为“二进制字符串”(字节被视为ISO-8859-1,因此每个charCodeAt对应一个字节),重新编码为UTF-8。 This would end up around 50% bigger than a plain file upload. 这将比普通文件上传大约50%。 Is it worth the slower upload to get the progress report? 获取进度报告是否值得上传较慢?

(God, if only browsers had a better UI to show how the upload was going, none of the endless scripting/Flash/Java/ActiveX nonsense would ever have been necessary. Come on, browser vendors, is a nice big info popup with a progress bar really too much to ask for?) (上帝,如果只有浏览器有一个更好的用户界面来显示上传的方式,那么无论是无休止的脚本/ Flash / Java / ActiveX废话都不是必需的。来吧,浏览器供应商,是一个很好的大信息弹出窗口进度条真的太要求了吗?)

Yes, in theory, although I would have to question the accuracy since Internet speed generally fluctuates (more-so if you aren't wired). 是的,从理论上讲,虽然我不得不质疑准确性,因为互联网速度通常会波动(如果你没有接线,那就更多了)。 It would probably jump around alot. 它可能会跳得很多。

Then again, what is an accurate progress bar? 那么,什么准确的进度条? I'd like to see one in Windows before I see one online! 在网上看到一个之前,我想在Windows中看到一个!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM