<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,傳輸發生錯誤