File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # 文件上传进度提示的多种实现方式
2+ ## 1. html5 File API实现带有进度提示的文件上传
3+ 现在大部分网站用Flash实现文件上传进度,还有些网站继续用` html <form> ` 的` enctype=multipart/form-data ` ,但需要服务器端的支持。因此,H5的file相关api是不二之选。
4+ ### 1.1 XMLHttpRequest Level 2新特性
5+ [ 访问 XMLHttpRequest Level 2] ( https://www.w3.org/TR/XMLHttpRequest2 )
6+ > 1 . 处理字节流,如File,Blob,FormData对象
7+ > 2 . 上传、下载进度事件
8+ > 3 . 跨站点请求
9+ > 4 . 允许创建匿名请求
10+ > 5 . 可以设置请求超时
11+
12+ ### 1.2 客户端可获取的信息
13+ 根据XHR2新特性,目前不依赖服务器能够客户端提供如下信息:
14+ 1 . 当前文件信息(文件名、大小、类型)
15+ 2 . 上传百分比进度条
16+ 3 . 上传速度、上传带宽
17+ 4 . 上传完成时间估算
18+ 5 . 已上传文件大小
19+ 6 . 服务器端响应(上传过程中页面未发生跳转等任何变化,可用此信息处理上传事件)
20+
21+ ### 1.3 Html5 Progress Event
22+ > total - 总字节数
23+ loaded - 已上传总字节数
24+ lengthComputable - 可计算的已上传字节
25+
26+ ### 1.4 浏览器支持情况
27+ Firefox 4.0 beta 6
28+ Chrome 6
29+ Safari 5.02
30+ IE 9 Beta 和 Opera 10.62 不支持
31+
32+ ### 1.5 Demo
33+
34+ ## 2 服务器计算IO流,客户端轮询
35+ ## 3 参考文章
36+ [ 参考文章] ( http://www.matlus.com/html5-file-upload-with-progress/ )
You can’t perform that action at this time.
0 commit comments