Skip to content

Commit c14e991

Browse files
文件上传md
1 parent 60f9c3c commit c14e991

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/)

0 commit comments

Comments
 (0)