[koa2]分片上传为什么前台progress事件中的loaded和total一直是2
路由用的koa-router, 后端代码:
router
.get('/', controller.index)
.post('/chunk', controller.uploadChunk)
uploadChunk: async function(ctx){
if(!ctx.request.fields){
return
}
await file.saveChunk(ctx.request.fields)
await file.mergeChunks(ctx.request.fields)
ctx.status = HTTP_STATUS.OK
}
前台代码:
xhr.addEventListener("progress", function (e) {
console.log('progress', e, e.loaded, e.total)
onProgress && onProgress()
}, false)
1 回复
找到原因了,原来是
xhr.upload.addEventListener("progress", function (e) {
console.log('progress', e, e.loaded, e.total)
onProgress && onProgress()
}, false)