我正在尝试使用XMLHttpRequest和file.slice将一些大文件上传到服务器.
我已经在文档和其他各种链接的帮助下做到了这一点.
由于上传大文件是一项很长的工作,我想为用户提供一个进度条.
经过一些更多的阅读后,我遇到了一个例子,从理论上讲,它完全符合我的需要.
通过获取示例代码并使其适应我的需求,我达成了
var upload =
{
blobs: [],
pageName: '',
bytesPerChunk: 20 * 1024 * 1024,
currentChunk: 0,
loaded: 0,
total: 0,
file: null,
fileName: "",
uploadChunk: function (blob, fileName, fileType) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.responseText) {
// alert(xhr.responseText);
}
}
};
xhr.addEventListener("load", function (evt) {
$("#dvProgressPrcent").html("100%");
$get('dvProgress').style.width = '100%';
}, false);
xhr.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var progress = …Run Code Online (Sandbox Code Playgroud)