Axios onUploadProgress only fires once on my machine

后端 未结 2 955
故里飘歌
故里飘歌 2021-01-18 03:52

If I use this fiddle https://jsfiddle.net/v70kou59/1/ everything works as expected

(function () {
    var output = document.getElementById(\'output\');
    d         


        
2条回答
  •  花落未央
    2021-01-18 04:40

    Because the new version changed.

    So you have to call progress instead of onUploadProgress

     static uploadImageFile(authId, userinfo, file, callback) {
            let url = AppConfig.domain + '/api/CoreUploads/uploadImg';
            let formData = new FormData();
            formData.append('realm', userinfo.realm);
            formData.append('fileurl', `users/${userinfo.id}/`);
            formData.append('cropData', "");
            formData.append('autoid', true);
            formData.append('image', file);
    
            return axios.post(url, formData, {
                timeout: 1000000,
                withCredentials: true,
                headers: {
                    'Authorization': authId,
                    'Content-type': 'multipart/form-data'
                },
                progress: function (progressEvent) {
                    let percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
                    callback(percentCompleted);
                }
            }).catch(e => {
                console.log(e);
    
            });
        }
    

提交回复
热议问题