我正在尝试跟踪帖子请求的进度,我只是从 uploadEventHandlers 获得了进展,但没有从 eventHandlers 获得进展(请参阅下面的代码)。我从 uploadEventHandlers 获得的进度包含传输的长度和总长度。但是我有这些问题:
$http({
url: baseUrlService.baseURL + 'importtifile',
method: 'POST',
data: myData
eventHandlers: {
progress: function(e) {
console.log(e);
}
},
uploadEventHandlers: {
progress: function(e) {
console.log(e);
}
}
}).then(
...
答案 0 :(得分:2)
注意:您可以通知用户,在上传文件达到100%后,服务器将执行其他工作。
这是您修改过的代码:
$http({
url: baseUrlService.baseURL + 'importtifile',
method: 'POST',
data: myData
eventHandlers: {
readystatechange: function(event) {
if(event.currentTarget.readyState === 4) {
console.log("readyState=4: Server has finished extra work!");
}
}
},
uploadEventHandlers: {
progress: function(e) {
if (e.lengthComputable) {
progress = Math.round(e.loaded * 100 / e.total);
console.log("progress: " + progress + "%");
if (e.loaded == e.total) {
console.log("File upload finished!");
console.log("Server will perform extra work now...");
}
}
}
}
}).then(
...