小幸运1997
小幸运1997
  • 发布:2020-09-24 15:31
  • 更新:2022-01-18 17:42
  • 阅读:2461

【报Bug】uni.uploadFile真机调试 后端接口无法获取文件

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 2.6.5

第三方开发者工具版本号: 1.03.2009140

基础库版本号: 2.13.0

项目创建方式: HBuilderX

操作步骤:

真机上传图片

预期结果:

{"data":{"attachmentId":852,"fileName":"wx81c7407cb7539a4e.o6zAJs5udYkdvBum6yHg39tjOSjY.eDza9YL29BbGc12dea7e8962a09e382d12a3623828ee.png","fileSize":"9523","filePath":"upload/complaint/20200924/1600929345892.png","insertTime":1600929345892},"success":true,"message":null}

实际结果:

{"data":null,"success":false,"message":null}
后端未获取到文件

bug描述:

uni.uploadFile真机调试 后端接口无法获取文件

采用uni.app开发,结合uview的u-upload组件

action: this.$H.common.baseurl + '/applets/commonattachment/upLoadFile',  
fileList: [],  
uploadData: {  
        'attType': 'complaint'  
    },  
header: {  
        'content-type': 'multipart/form-data',  
        'Connection':'keep-alive'  
    }  

                               //上传方法  
                                uni.uploadFile({  
                url: this.action,  
                filePath: this.lists[index].url,  
                name: this.name,  
                formData: this.formData,  
                header: this.header,  
                success: res => {  
                    // 判断是否json字符串,将其转为json格式  
                    let data = this.toJson && this.$u.test.jsonString(res.data) ? JSON.parse(res.data) : res.data;  
                    console.log(data)  
                    console.log(res)  
                    if (![200, 201, 204].includes(res.statusCode) || data.success == false) {  
                        this.uploadError(index, data);  
                    } else {  
                        // 上传成功  
                        this.lists[index].response = data;  
                        this.lists[index].progress = 100;  
                        this.lists[index].error = false;  
                        this.$emit('on-success', data, index, this.lists, this.index);  
                    }  
                },  
                fail: e => {  
                    this.uploadError(index, e);  
                },  
                complete: res => {  
                    uni.hideLoading();  
                    this.uploading = false;  
                    this.uploadFile(index + 1);  
                    this.$emit('on-change', res, index, this.lists, this.index);  
                }  
            });

开发者工具这边请求https是没问题的:

返回结果:

不检验合法域名关闭:

真机调试:


结果

在后端接口日志查看是真机时没有获取到文件,图中①迭代器获取文件name为空。(期间使用@RequestParam("file") MultipartFile file 获取文件依旧为空)

请问这个问题有什么解决思路吗

2020-09-24 15:31 负责人:无 分享
已邀请:
项目目录

项目目录

同问

同样的代码打包成H5可以

该问题目前已经被锁定, 无法添加新回复