zoukankan      html  css  js  c++  java
  • 云开发检验图片是否有违规内容

    客户端

    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;
      }
    }
  • 相关阅读:
    脚手架自建从开始到发布
    零散点总结
    2019.3.7 chrome72下载图片卡死问题
    2019.2.18 一九年的新篇章
    2018.10.12 布局终结
    2018.7.23 放大缩小菜单
    2018.7.19 横向收缩菜单动画
    2018.6.8 openlayers.js学习(汇总)
    Elasticsearch 排序
    easyui tree树节点上移下移 选中节点加背景色
  • 原文地址:https://www.cnblogs.com/zwyboom/p/11330128.html
Copyright © 2011-2022 走看看