uploadFilePromise(file) {
console.log(file);
let _this = this
return new Promise((resolve, reject) => {
uni.uploadFile({
url: BASE_URL_API + 'app/upload/file',
filePath: file.url,//临时路径
name: 'file', //对应后台接口参数名
method: 'POST',
header: {
'token': _this.$config.getToke()
},
formData: {
//要上传的文件
file: file
},
success(res) {
console.log(res);
if (res.path) {
that.imageUrls = res.path;
console.log(that.imageUrls);
}
},
fail(res) {
console.log(res);
uni.showToast({
icon: 'error',
title: '图片上传失败!'
})
}
})
})
},
uniapp formdata 单文件上传
于 2024-03-04 14:23:18 首次发布