pagekit / vue-resource

The HTTP client for Vue.js
MIT License
10.08k stars 1.6k forks source link

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

Open hualvm opened 7 years ago

hualvm commented 7 years ago

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】报错:

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?

thWinterSun commented 6 years ago

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