Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

怎样才能获得上传的进度(how to get the upload progress)? #581

Open
hualvm opened this issue Mar 14, 2017 · 1 comment
Open

Comments

@hualvm
Copy link

hualvm commented Mar 14, 2017

Reproduction Link

1、第一种写法(the First method)
……
let formData = new window.FormData()
formData.append('roomId', roomId)
formData.append('file', file)
this.$http.post(url, formData, {
headers: {'Content-Type': 'multipart/form-data'},
progress: function (e) {
console.log(123456)
console.log(e.loaded / e.total * 100)
}
}).then(function (response) {
console.log('success')
console.log(response)
}, function (response) {
console.log('err')
})
image

【chrome】报错:
image

【server】报错:
[Thread: http-bio-80-exec-6]-[com.jfinal.core.ActionHandler.handle()]: /api/live_m/addZip?mid=64&token=e10adc3949ba59abbe56e057f20f883e
java.lang.RuntimeException: java.io.IOException: Posted content type isn't multipart/form-data

image

=========================================================================
2、第二种写法(the Second method)
……
let formData = new window.FormData()
formData.append('roomId', roomId)
formData.append('file', file)
this.$http.post(url, formData, {
headers: {'Content-Type': 'multipart/form-data'}
}, {
progress: function (e) {
console.log(123456)
console.log(e.loaded / e.total * 100)
}
}).then(function (response) {
console.log('success')
console.log(response)
}, function (response) {
console.log('err')
})
image

结果:
image

【server】: no Error

Steps to reproduce

What is Expected?

请问怎么样写才能得到上传的进度?
Excuse me, how to get the upload progress ?

What is actually happening?

@hualvm hualvm changed the title 怎样才能获得上传的进度 怎样才能获得上传的进度(how to get the upload progress)? Mar 14, 2017
@thWinterSun
Copy link

你好,不知道你的问题解决没有,我也遇到了相同的问题找不到答案。后来我使用axios做上传交互,使用axios的onUploadProgress方法就可以获取loaded和total等数据了

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants