我通过canvas等比例压缩,尺寸尽量小,完美实现
IOS手机图片安全检测imgSecChe,报Error: errCode: -1 错误?真机调试报这个错误,提示max size,我上传的图片很小的。Android手机没问题,现在发现iPhone6有问题。 APPID:wxa0c17091265340da Error: errCode: -1 | errMsg: cloud.callFunction:fail Error: data exceed max size (callId: 1586489164793-0.5581622445325081) (trace: 11:26:4 start->11:26:11 system error (Error: data exceed max size), retry->11:26:17 system error (Error: data exceed max size), retry->11:26:21 system error (Error: data exceed max size), abort); at cloud.callFunction api; at new u (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:233907) at d (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:234414) at f (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:234509) at eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:399226) at t (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:65617) at eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:65739) at e (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:68192) at e.exports (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:27005) at y. (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:32408) at Number.r (eval at n.call.document (runtime.js?devtools_ignore=true:1), :2:32107) [图片] 刚才有开始报404012错误了 [图片] [图片] 云函数的写法,请求的写法 const cloud = require('wx-server-sdk') cloud.init() // 云函数入口函数 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; } } 请求 //检查图片 imgcheck: function () { var that = this; wx.compressImage({ src: this.data.imgbg, // 图片路径 quality: 10, // 压缩质量 success(res) { console.log('图片' + res.tempFilePath) wx.getFileInfo({ filePath: res.tempFilePath, success(resinfo) { console.log('图片压缩后的尺寸' + resinfo.size) if (resinfo.size < 600 * 1024) { wx.getFileSystemManager().readFile({ filePath: res.tempFilePath, success: buffer => { console.log('getImageInfo' + JSON.stringify(buffer)) console.log('getImageInfo' + buffer) console.log('getImageInfo' + buffer.data) wx.cloud.callFunction({ name: 'imgcheck', data: { value: buffer.data }, success: res => { console.log('图片检测成功') console.log(JSON.stringify(res)) console.log(res.result.errCode) if (res.result.errCode == '87014') { wx.hideLoading() wx.showModal({ title: '提醒', content: '此图片暂不可用', showCancel: false }) } else { that.updateimg(); console.log('图片正常') } }, fail: err => { console.log(err) }, complete: () => { } }) }, fail: err => { console.log(err) } }) } else { wx.hideLoading() wx.showModal({ content: '图片过大,请选小点的(๑❛ᴗ❛๑)', showCancel: false }) } } }) }, }) },
2020-04-12