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

客户端

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;
  }
}

 

转载于:https://www.cnblogs.com/zwyboom/p/11330128.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值