<button @click='beforeUpload' >上传文件</button>
beforeUpload() {
const that = this
const count = 1
uni.chooseImage({
count:count,
success:(res)=> {
const tempFilePaths = res.tempFilePaths;
uni.uploadFile({ //循环调用上传单个文件的接口,实现多文件上传
url: 'http//:xxxxxxx', //仅为示例,非真实的接口地址
file: res.tempFiles[0],
name: 'file',
fileType:'image',
header:{
'Authorization': uni.getStorageSync('token') ? "Bearer " +uni.getStorageSync('token') : '',
},
success: function (uploadFileRes) {
}
});
}
})
}
默认file值以formData格式传输,header中不需要配置Content-Type,若配置Content-Type,传输发生错误