我想用 wx.chooseImage从手机端选择一张图片,再通过cloud.uploadFile上传到云,然后想用ocr.idcard对这个图片做识别,
但是这个云端返回的图片链接并不可用,想问的是这个ocr.idcard到底怎么使用的,必须要把图片传给服务器,然后服务器给图片地址吗?
代码如下
扫描小程序码分享
我想用 wx.chooseImage从手机端选择一张图片,再通过cloud.uploadFile上传到云,然后想用ocr.idcard对这个图片做识别,
但是这个云端返回的图片链接并不可用,想问的是这个ocr.idcard到底怎么使用的,必须要把图片传给服务器,然后服务器给图片地址吗?
代码如下
传arrayBuffer
小程序端
let fs = wx.getFileSystemManager()
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
console.log(res)
wx.cloud.callFunction({
name:'xxxxxxx',
data:{
imgType: res.tempFilePaths[0].split('.').pop(),
imgArrayBuffer: fs.readFileSync(res.tempFilePaths[0])
},
success(r) {
console.log(r)
},
fail(e) {
console.log(e)
}
})
}
})
============================
云函数端
cloud.openapi.ocr.idcard({
type: 'photo',
img: {
contentType: 'image/'+event.imgType,
value: Buffer.from(event.imgArrayBuffer)
}
})
小程序端wx.chooseImage({count: 1,sizeType: ['original', 'compressed'],sourceType: ['album', 'camera'],success(res) {console.log(res)let type = res.tempFilePaths[0].split('.').pop()wx.cloud.uploadFile({cloudPath: 'idcard.' + type,filePath: res.tempFilePaths[0]}).then(res=>{console.log(res.fileID)wx.cloud.callFunction({name: 'xxxxxxx',data: {fileID: res.fileID},success(r) {console.log(r)},fail(e) {console.log(e)}})})}})====================云函数端const result = await cloud.getTempFileURL({fileList: [event.fileID],})cloud.openapi.ocr.idcard({type: 'photo',imgUrl: result.fileList[0].tempFileURL})云函数是没问题的,我想问的是chooseImage 选了之后,把图片通过wx.cloud.uploadFile传到云服务,云服务为什么没返回图片地址,有的话就可以用ocr.idcard怎么去识别了
http://www.f6m88vra.com/debug/wxadoc/dev/api-backend/open-api/ocr/ocr.idcard.html 就看到的这个文档来说,需要权限,相关权限有没有配置申请?