😏😏😏
for循环,图片批量鉴黄?我理想中的结果是一张一张图片鉴黄,把鉴定违规的图片删除,但是现在的结果如图: [图片] //上传图片 onChangeFlockData: async function (e) { let imgUrls = e.detail.all; //上传的图片数组 for (let i = 0; i < imgUrls.length; i++) { await this.imgInfoCheck(imgUrls[i].url) } }, //获取图片信息 imgInfoCheck: async function (url) { wx.getImageInfo({ src: url, }).then(async (res) => { console.log("图片信息:", res) const imgInfo = res.path; const imgWidth = res.width; const imgHeight = res.height; await this._compressImage(imgInfo, imgWidth, imgHeight); }) }, //图片压缩 _compressImage: async function (imgInfo, imgWidth, imgHeight) { const query = wx.createSelectorQuery() query.select('#canvas') .fields({ node: true, size: true }) .exec(res => { const canvas = res[0].node; const ctx = canvas.getContext('2d'); const dpr = wx.getSystemInfoSync().pixelRatio; const imgW = Math.trunc(imgWidth / dpr); const imgH = Math.trunc(imgW / imgWidth * imgHeight); canvas.width = imgW; canvas.height = imgH; ctx.clearRect(0, 0, imgW, imgH); this.setData({ canvasWidth: imgW, canvasHeight: imgH }); let imageObj = canvas.createImage(); imageObj.src = imgInfo; imageObj.onload = (res) => { ctx.drawImage(imageObj, 0, 0, imgW, imgH) }; const cfgSave = { fileType: "jpg", quality: 0.5, width: imgW, height: imgH, destWidth: imgW, destHeight: imgH, canvas: canvas, }; wx.canvasToTempFilePath({ ...cfgSave, }).then(async res => { let tempUrl = res.tempFilePath console.log("压缩后图片:", res) await this.imgSecCheck(tempUrl) }) }) }, //图片送审 imgSecCheck: async function (tempUrl) { wx.showLoading({ mask: true }); wx.getFileSystemManager().readFile({ filePath: tempUrl, encoding: "base64", success: function (res) { let imgBuffer = res.data wx.cloud.callFunction({ name: "msgSecCheck", data: { type: 'imgSecCheckBuffer', //以buffer方式上传送审 value: imgBuffer, } }).then(res => { console.log("图片检测结果:", res.result.errCode) wx.hideLoading() if (res.result.errCode === 87014) { wx.hideLoading() wx.showToast({ title: '图片含有违法违规内容', icon: 'none' }) return } // this._uploadImg(tempUrl) }).catch(err => { console.log(err) wx.hideLoading() wx.showModal({ title: '提示', content: '图片尺寸过大,请调整图片尺寸', success(res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) }) }, fail: err => { console.error(err); } }) },
2021-05-16😁
本地调试可以正常返回云函数结果内容,关闭云函数本地调试之后云函数报错,上传部署云函数所有文件,为啥?[图片] 云函数: const cloud = require('wx-server-sdk'); const translate = require('@vitalets/google-translate-api'); cloud.init({ env: "wechat-online-a4c8d5", traceUser: true }) // 云函数入口函数 exports.main = async (event, context) => { return await translate(event.translateContent, { from: event.from, to: event.to, tld: 'cn', client: 'gtx' }); } 客户端调用: const data = this.getTranslatData(); let _this = this; wx.cloud.callFunction({ name: 'translate', data: data, success: res => { console.log('[云函数] [translate] call success: ', res.result); _this.setData({ translateResult: res.result.text, isTranslated: true, isLoading: false }) }, fail: err => { console.error('[云函数] [translate] 调用失败', err) _this.setData({ translateResult: null, isTranslated: false, isLoading: false }) } }); 关闭云函数之后调用结果: VM125:1 [云函数] [translate] 调用失败 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 3c719654-7161-11ea-ab05-525400192d0e, cloud function service error code -504002, error message EROFS: read-only file system, mkdir '/home/qcloud'; at cloud.callFunction api; at new u (WAService.js:1) at d (WAService.js:1) at f (WAService.js:1) at Function.success (WAService.js:1) at WAService.js:1 at C (WAService.js:1) at i.<anonymous> (WAService.js:1) at i.emit (WAService.js:1) at Rs (WAService.js:1) at WAService.js:1 请问这是啥原因导致的呢,开发者工具是最新的版本了
2021-05-16j
小程序在云函数勾选本地调试模式正常,但关闭云函数本地调试后返回401?API/组件名称: 云函数 微信版本号:3.2.1.132 基础库版本号:2.11.0[407] 云函数代码如下: const cloud = require('wx-server-sdk') var rp = require('request-promise') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 云函数入口函数 exports.main = async (event, context) => { let url = 'https://api.vultr.com/v2/instances' let tokenheader = "Bearer *************"; return await rp({ url: url, headers: { 'Authorization': tokenheader, } }).then(function (res) { return res }).catch(function (err) { return err }); 期望结果:云函数正常返回200 实际结果:在云开发-云函数-云函数本地调试下,函数正常返回,关闭云函数本地调试报错: [图片] 查看调试控制台network,发现异常时: [图片] Response: { "errCode": -404011, "errMsg": "Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID ed479fd2-b627-11eb-a01d-5254002d4a45, cloud function service error code -504002, error message HTTPError: Response code 401 (Unauthorized)\n at EventEmitter.emitter.on (/var/user/node_modules/got/source/as-promise.js:74:19)\n at process._tickCallback (internal/process/next_tick.js:68:7); at cloud.callFunction api; " } 请求像是没有经过云函数转发到我的服务器后端。
2021-05-16