从小程序云函数调用imgSecCheck()时一直报41005错误,但是对应的media已经按文档设置。
errCode: 41005 | errMsg: openapi.security.imgSecCheck:fail media data missing hint: [xKvxiA04673955]
错误信息提示
imgSecCheck() is triggered from cloud with event:
{action: "imgSecCheck", contentType: "image/jpg", buffer: {…}}
action: "imgSecCheck"
buffer: {type: "Buffer", data: Array(15006)}
contentType: "image/jpg"
__proto__: Object
exception during imgSecCheck, e: Error: errCode: 41005 | errMsg: openapi.security.imgSecCheck:fail media data missing hint: [xKvxiA04673955]
at callWXOpenAPI (/.../cloudfunctions/openapi/node_modules/wx-server-sdk/index.js:2267:31)
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at async imgSecCheck (/.../cloudfunctions/openapi/index.js:43:15)
小程序云开发服务端代码段
// 图片内容检测
async function imgSecCheck(event) {
console.debug('imgSecCheck() is triggered from cloud with event: ', event)
try {
let res = await cloud.openapi.security.imgSecCheck({
media: {
contentType: event.contentType, // 'image/png',
value: event.value, // Buffer
}
})
return res
}
catch (e) {
console.error('exception during imgSecCheck, e: ', e)
return e
}
}
你可以试试这篇文章解决方式:完美解决
https://mp.weixin.qq.com/s/o77bLIfCEkHq3acmqS4Tyw