360手机 N6 Pro,iPhone 8 Plus(MQ8F2CH/A),使用wx.chooseImage拍照,wx.compressImage压缩图片后调用wx.uploadFile报错,在wx.uploadFile的success回调里拿到了上传报错信息,没有走fail回调。其他机型未发现问题。
图片路径获取正常:
代码片段:
function wxChooseImageWeb(quality = default_quality, count = 1, sourceType = ['camera'], sizeType = ['compressed']) {
return new Promise((resolve, reject) => {
chooseImage(count, sourceType, sizeType).then(tempFiles => {
compressImage(tempFiles[0].path, quality).then(compressImagePath => {
upLoadImage(compressImagePath).then(res => {
resolve(res.data);
}).catch(res => {
reject(res);
})
}).catch(() => {
upLoadImage(tempFiles[0].path).then(res => {
resolve(res.data);
}).catch(res => {
reject(res);
})
});
}).catch(res => {
reject(res);
});
})
}
function chooseImage(count = 1, sourceType = ['camera'], sizeType = ['compressed']) {
return new Promise((resolve, reject) => {
wx.chooseImage({
count: count,
sizeType: sizeType,
sourceType: sourceType,
success(res) {
const tempFiles = res.tempFiles
resolve(tempFiles);
},
fail(res) {
log.warn("调起选择照片组件错误(chooseImage)");
log.warn({res});
reject(res);
}
})
})
}
function compressImage(filePath, quality = default_quality) {
return new Promise((resolve, reject) => {
wx.compressImage({
src: filePath, // 图片路径
quality: quality, // 压缩质量
success(res) {
console.log('压缩图片路径:', res.tempFilePath)
resolve(res.tempFilePath);
},
fail(res) {
log.warn("压缩图片错误(compressImage)");
log.warn({res});
log.warn(res.errMsg)
reject(res);
}
})
})
}
function upLoadImage(filePath) {
console.log('upload image filePath', filePath)
return new Promise((resolve, reject) => {
wx.uploadFile({
url: config.imgUpload,
filePath: filePath,
header: {
"Content-Type": "multipart/form-data; boundary=----pxt1Wc2xg7qmKkE6pyH"
},
name: 'file',
success: function (res) {
// 在success里这里拿到了上传报错信息,没有走fail
res.data = JSON.parse(res.data);
console.log('res.data', res.data)
util.resultUtil(res).then(() => {
resolve(res.data);
}).catch(() => {
reject(res.data);
});
},
fail: function(err) {
console.log(err)
}
})
}
报错信息是什么?最重要的部分你不发