学渣某某人
学渣某某人
  • 发布:2019-12-13 10:44
  • 更新:2019-12-13 15:30
  • 阅读:2458

uniapp 上传图片再传其他的参数报错

分类:uni-app

在上图片时,希望和其他的参数一同传过去

图片信息提前进行保存了,也就是imgFiles
传入后台时,提示错误信息:
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=--------------------------472725781421473109393800;charset=UTF-8' not supported

userForm中的参数可以收到,但是文件后台接收不到,目前只能进行分开上传,所以,希望可以实现只调用一个接口

感谢各位大佬

2019-12-13 10:44 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com - 我是小提莫

多文件上次,后台循环去接收,前端这样写:```javascript
let imgs;
if (this.imageList.length != 0) {
imgs = this.imageList.map((value, index) => {
return {
name: "file" + index,
uri: value
}
});
} else{
imgs = '';
}

uni.uploadFile({
url: this.$serverUrlhunlian + '/user/editUserdataFile',
methods: 'POST',
files: imgs,
filePath: '',
name:'file',
formData: jsons,
header: {
'Content-Type': 'multipart/form-data',
'token': this.$store.state.user.token,
},
success: (res) => {
uni.hideLoading();
var dat = JSON.parse(res.data);
console.log(JSON.stringify(dat));
// {"msg":"操作失败","flag":false,"status":"error"}
if (dat.flag) {
uni.hideLoading();
uni.showToast({
title: '修改成功!'
});
setTimeout(function(){
uni.navigateBack({
delta: 1
})
}, 1000)
}else{
uni.showToast({
title: '提交失败,请检查是否有特殊字符',
icon: 'none'
})
}

                    },  
                    fail: (res) => {  
                        //console.log(res);  
                        uni.hideLoading();  
                        uni.showToast({  
                            title: '请求失败,请检查网络',  
                            icon: 'none'  
                        })  
                    }  
                });


选择图片: ```chooseImg() { //选择图片  
                uni.chooseImage({  
                    sourceType: ["camera", "album"],  
                    sizeType: ["compressed"],  
                    count: 6 - this.imageLists.length - this.imageList.length,  
                    success: (res) => {  
                        //console.log(JSON.stringify(res))  
                            this.imageList = this.imageList.concat(res.tempFilePaths);  
                    }  
                })  
            },```

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