麻烦大神帮忙看一下,说格式错了!蒙圈!我可是照搬官方教程啊!!
云函数:
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
console.log("event.img:::::::::::::::::::")
console.log(event.img);
const imgmsg = (await cloud.downloadFile({
fileID: event.img,
})).fileContent;
console.log("imgmsg:::::::::::::::::::")
console.log(imgmsg);
return cloud.openapi.security.imgSecCheck({
media: {
contenType: 'image/png',
value:imgmsg
}
})
}
返回结果
{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Error: errCode: 47001 |
errMsg: openapi.security.imgSecCheck:fail data format error rid: 61297c8e-346fc71a-4662d736\n
at callWXOpenAPI (/var/user/node_modules/wx-server-sdk/index.js:2392:31)\n
at process._tickCallback (internal/process/next_tick.js:68:7)","statusCode":430}
日志
START
event.img:::::::::::::::::::
cloud:
当前未指定env,将默认使用第一个创建的环境!
imgmsg:::::::::::::::::::
{
"type": "Buffer",
"data": [
137,
80,
78,
71,
......................
你好,报错47001,数据格式错误。
可参考:https://developers.weixin.qq.com/community/develop/article/doc/00062c5c7a8ec834dc692913156013
https://developers.weixin.qq.com/community/develop/article/doc/00024a78ec00188a565a19c545b013
requests.post(url, files={'media': open('tmp.jpg','rb')}).json() requests.post(url, files={'media': (requests.get("img_url").content)},headers={'Content-Type': 'multipart/form-data'}).json()
我用python调用图片的检测, url是拼接了token之后的请求地址。以上两种方式都返回错误47001。我目前的场景不能直接把小程序前端上传的图片直接去调用微信检测。请问下我这个场景下要怎么做。
In [51]: requests.post(url, files={'media': (requests.get(img_url).content)},headers={'Content-Type': 'multipart/form-data'})
...: .json()
Out[51]: {'errcode': 0, 'errmsg': 'ok'}