相关文档
https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html
实现方案
调用后端提供的上传文件接口 直接调用 ,接口给返回需要的数据接口 , 本人是只写小程序前端,所以后端。。。
以下是实现代码
<button class="scan-btn" bindtap='chooseImageOrPhotograph'>扫身份证 </button>
chooseImageOrPhotograph() {
const that = this
wx.chooseImage({
count: 1,
sourceType: type,
success(e) {
const imageSrc = e.tempFilePaths[0]
wx.uploadFile({
// 后端提供的上传文件地址 按照真实地址添加
url: `http: ........`,
filePath: imageSrc,
name: 'cardFile',
header: {
// 根据需求添加
"X-Token": token
},
success(res: any) {
// 开发者服务器返回的数据
console.error("res 获取",res)
}
})
},
fail(err) {
console.error("err", err)
}
})
},
今日份分享就到这里啦,希望本篇文章能够帮助到你们呀~