XHR进展事件太快到达

时间:2013-04-28 18:52:28

标签: ajax amazon-s3 xmlhttprequest cors

我正在使用html表单和ajax直接上传到S3。它运行良好,文件上传。我的问题是进度事件来得太快了。像所有这些人一样,在上传开始时会立即解雇高达99.9%的人。

var fd = new FormData();

// put data from the form to FormData object 
$.each( $('#upload-form').serializeArray(), function(i, field) {
        fd.append(field.name, field.value);
});

// add selected filename to the form data
var file = document.getElementById('path-to-file').files[0];
fd.append("file", file);

var xhr = getXmlHttpRequest(); // cross-browser implementation 

xhr.upload.addEventListener("progress", function(e) {
    console.log(e.loaded + "/" + e.total);
});

xhr.open('POST', 'http://mybucket.s3.amazonaws.com/', true); 
xhr.send(fd);   

也试过这种方式

xhr.upload.onprogress = function(evt)
{
    if (evt.lengthComputable)
    {
        console.log(e.loaded + "/" + e.total);
    }
};

浏览器日志如下所示:

[22:54:47.245] POST http://mybucket.s3.amazonaws.com/ 
[22:54:47.287] 359865/5680475
[22:54:47.330] 1408441/5680475
[22:54:47.408] 2751929/5680475
[22:54:47.449] 3964345/5680475
[22:54:47.509] 5668281/5680475

然后上传5M文件所需的时间没有任何内容。

如果浏览器信息相关,我有Firefox 20.0.1

0 个答案:

没有答案