雲開發檢驗圖片是否有違規內容


客戶端

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM