Symptom
The following two pictures, the first one can be shared on WeChat, and the second one reports the error "wxShareAPI.sendReq return false"
// Pictures that can be shared on : 1610ac79cef6d6 https://tws.oss.cnweisou.com/images/23068/2020/12/aq998Lb8W94ixL8142z6677WvIg19x.png
// Pictures that cannot be shared on : 1610ac79cef6ef https://tws.oss.cnweisou.com/images/23068/2020/12/j280VVZaXnrjJAJvRSjV8JzSvHV11N.png
problem analysis
WeChat has restrictions on sharing large images. The upper limit is about 250kb. If the image is too large, an error will be reported. Therefore, it is necessary to compress the large image and share it.
Note: The current image compression interface only supports local image compression. If you need to compress network images, it is recommended to save them locally before compressing them.
Solution
The sample code is as follows:
share: function () {
image.compressImage({
uri: "/Common/2.png", //需要压缩的图片,只支持本地图片
quality: 80,
ratio: 2,
format: "PNG",
success: function (data) {
console.log(data.uri)
share.share({
shareType: 0,
title: "我是标题",
summary: "我是摘要",
imagePath: data.uri,
targetUrl: "http://www.huawei.com",
success: function () {
console.log("share success");
},
fail: function (data, code) {
console.log("handling fail, code=" + code + ", data=" + data);
}
})
},
fail: function (data, code) {
console.log("handling fail, code=" + code);
}
})
}
Quick Application Document
Picture API interface:
https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-api-image
Third-party sharing interface:
https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-api-thirdshare
Original link: https://developer.huawei.com/consumer/cn/forum/topic/0203471559251110260?fid=0101271690375130218
Original Author: Mayism
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。