清河树人
清河树人
  • 发布:2024-03-28 17:43
  • 更新:2024-03-28 17:43
  • 阅读:445

【报Bug】uni.uploadFile上传文件时,uploadTask.onProgressUpdate 监听到的progress(上传进度)会超过100%,导致上传失败

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 3.99

手机系统: Android

手机系统版本号: Android 10

手机厂商: 小米

手机机型: Redmi 9A

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
                              const uploadTask = uni.uploadFile({  
                url: 'test.com',//输入你的bucketname.endpoint  
                filePath: tapeUrl,  
                name: 'file',  
                formData: {  
                    key: upload_url,  
                    policy: Oss.policy, // 输入你获取的的policy  
                    OSSAccessKeyId: Oss.OSSAccessKeyId, // 输入你的AccessKeyId  
                    success_action_status: '200', // 让服务端返回200,不然,默认会返回204  
                    signature: Oss.signature // 输入你获取的的signature  
                },  
                success: res => {  
                    if(res.statusCode == '200'){  
                        console.log('上传成功');  
                        this.upload_request(1, val)  
                    }else{  
                        console.log('失败');  
                    }  
                },  
                fail: (err) => {  
                    console.log(err, '失败了');  
                    this.upload_request(0, val)  

                }  
            });  

            uploadTask.onProgressUpdate((res) => {  
                console.log('上传进度' + res.progress);  
                console.log('已经上传的数据长度' + res.totalBytesSent);  
                console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);  

                // 测试条件,取消上传任务。  
                // if (res.progress > 50) {  
                //  uploadTask.abort();  
                // }  
            });

操作步骤:

上传文件进度超过100%导致上传失败

预期结果:

进度100% 上传成功

实际结果:

进度超过100% 上传失败

bug描述:

17:24:53.498 上传进度37 at pages/info/info.vue:190
17:24:53.504 已经上传的数据长度10240 at pages/info/info.vue:191
17:24:53.504 预期需要上传的数据总长度27041 at pages/info/info.vue:192
17:24:53.509 上传进度75 at pages/info/info.vue:190
17:24:53.509 已经上传的数据长度20480 at pages/info/info.vue:191
17:24:53.509 预期需要上传的数据总长度27041 at pages/info/info.vue:192
17:24:53.516 上传进度102 at pages/info/info.vue:190
17:24:53.517 已经上传的数据长度27648 at pages/info/info.vue:191
17:24:53.521 预期需要上传的数据总长度27041 at pages/info/info.vue:192
17:24:53.522 上传进度102 at pages/info/info.vue:190
17:24:53.522 已经上传的数据长度27648 at pages/info/info.vue:191
17:24:53.526 预期需要上传的数据总长度27041 at pages/info/info.vue:192
17:24:53.527 [Object] {"errMsg":"uploadFile:fail undefined"} , 失败了 at pages/info/info.vue:182

上传的文件为什么进度会超过100呢,一超过一百就直接走fail回调,也没有回调信息

2024-03-28 17:43 负责人:无 分享
已邀请:

要回复问题请先登录注册