不知道问题出在哪里?
一、云函数部分
config.json:
{
"permissions": {
"openapi": [
"security.imgSecCheck"
]
}
}
index.js:
const cloud = require('wx-server-sdk');
cloud.init({env:cloud.DYNAMIC_CURRENT_ENV,})
exports.main = async(event, context) => {
try {
const result = await cloud.openapi.security.imgSecCheck({
media:{
header:{'Content-Type':'application/octet-stream'},
contentType:'image/png',
value:Buffer.from(event.value)
}
})
return result
} catch (err) {
return err
}
}
二、前端js:
onUploadImg: function () {
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success:res =>{
const filePaths = res.tempFilePaths[0]
if(filePaths && filePaths > 1024*1024){
tips('图片不能大于1M')
return
}
console.log('res.tempFilePaths[0]: ',res.tempFilePaths[0])
wx.getFileSystemManager().readFile({
encoding:'base64',
filePath:filePaths,
success:res => {
var buffer = res.data
tips('图片检测中')
console.log('readFile: ',buffer)
wx.cloud.callFunction({
name:'imgCheck',
data:{
value:buffer
},
success : res1 => {
console.log('1: ',res1.result)
if(res1.result.errCode == 0){
}
if(res1.result.errCode == 87014){
}
},
fail:err => {
}
})
}
})
}
})
},
上图是选择图片后,调用imgcheck云函数的结果,result值为空,所以两个判断没起作用,无法验证图片
你失败return err,err会有result吗???