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


华为开发者论坛
352 声望56 粉丝

华为开发者论坛是一个为开发者提供信息传播、开发交流、技术分享的交流空间。开发者可以在此获取技术干货、华为源码开放、HMS最新活动等信息,欢迎大家来交流分享!


引用和评论

0 条评论