其他分享
首页 > 其他分享> > 云开发检验图片是否有违规内容

云开发检验图片是否有违规内容

作者:互联网

客户端

mIsImg() {
var that = this
wx.chooseImage({
count: 1,
sourceType: ['album'],
success: function(res) {
if (!res.tempFilePaths[0]) {
return;
}
console.log(JSON.stringify(res))
if (res.tempFiles[0] && res.tempFiles[0].size > 1024 * 1024) {
wx.showToast({
title: '图片不能大于1M',
icon: 'none'
})
return;
}
wx.getFileSystemManager().readFile({
filePath: res.tempFilePaths[0],
success: buffer => {
console.log(buffer.data)
wx.cloud.callFunction({
name: 'imgCheck',
data: {
value: buffer.data
}
}).then(
imgRes => {
console.log(JSON.stringify(imgRes))
if (imgRes.result.errorCode == '87014') {
wx.showToast({
title: '图片含有违法违规内容',
icon: 'none'
})
return
} else {
that.$store.state.isImg = res.tempFilePaths[0]
//图片正常
}

}
)
},
fail: err => {
console.log(err)
}
})
}
})
},

 

云函数

config.json

{
  "permissions": {
    "openapi": [
      "security.imgSecCheck"
    ]
  }
}

js

const cloud = require('wx-server-sdk')
cloud.init({
  env: 'test-vc0ep' // 你的环境ID
})
exports.main = async (event, context) => {
  const { value } = event;
  try {
    const res = await cloud.openapi.security.imgSecCheck({
      media: {
        header: {
        'Content-Type': 'application/octet-stream'},
          contentType: 'image/png',
          value: Buffer.from(value)
        }
      })
    return res;
  } catch (err) {
    return err;
  }
}

 

标签:return,log,res,检验,违规,console,图片,cloud,wx
来源: https://www.cnblogs.com/zwyboom/p/11330128.html