以下代码为上传图片代码,已经标注了compressed,但还是有部分手机未被压缩(机型包含华为P40,Redmi K40,OPPO A55),还是原图传上去了。想要用wx.compressImage压缩,但是接口一直提示未找到文件路径报错。{errMsg: "compressImage:fail file doesn't exist"}
wx.chooseImage({
count: 3 - imgs.length, // 默认9
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
//var imgs = that.data.imgs;
console.log('tempFilePaths',tempFilePaths);
for (var i = 0; i < tempFilePaths.length; i++) {
let imgtemp = tempFilePaths[i];
const src = tempFilePaths[i];
console.log(src);
//压缩
wx.compressImage({
src: src,
quality:40,
success: compres => {
console.log(src);
console.log("压缩");
console.log(compres);
},
fail: compres => {
console.log(typeof(src), src);
console.log(compres);
},
})
if (imgs.length >= 9) {
that.setData({
imgs: imgs
});
return false;
} else {
imgs.push(imgtemp);
}
}
// console.log(imgs);
that.setData({
imgs: imgs
});
}
});
https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.compressImage.html
检查下src?
{errMsg: "compressImage:ok", tempFilePath: "http://tmp/rkReN0BUyXe41f5b13922b35b64d5d57a742d6bd1021."}