真机调试报这个错误,提示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
})
}
}
})
},
})
},
我通过canvas等比例压缩,尺寸尽量小,完美实现
有遇到过,图片裁剪后变大了,调用云函数时data太大。iPhone 6sp ,放弃了图片裁剪
console.log(picH / picW * 200)
ctx.drawImage(tempFilePaths[0], 0, 0, 100, parseInt(picH / picW * 100)) //按比例对图片进行画图
ctx.draw(false, function () {
//把画好的图 描下来,写成临时文件
wx.canvasToTempFilePath({
x: -200,
y: -200,
width: 100,
height: parseInt(picH / picW * 100),
destWidth: 100,
destHeight: parseInt(picH / picW * 100),
canvasId: 'firstCanvas',
success: function (res) {
console.log(res.tempFilePath)
upload(that, res.tempFilePath);
}
})
})
有人遇到过这种情况没
我怀疑是文件名的问题