uniapp 中 uni.uploadFile 文件上传踩坑
作者:互联网
<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,传输发生错误
标签:count,uniapp,const,uploadFile,res,file,uni,上传 来源: https://www.cnblogs.com/wwxdxgb/p/15926497.html