简体   繁体   中英

How to share an array of image file links or multiple images through socialsharing plugin in ionic?

I am trying to share an array of dynamically created image file links through social sharing plugin in ionicv4. Right now I am testing it with WhatsApp. But it gives me a TS error that can not pass arr[] in type string. I do understand this error but need a solution to this. i have done something like

this.socialSharing.shareViaWhatsApp(null, imageArr , null);

I think the 2nd parameter should be a string, and your imageArr variable is an array. Try to pass a string instead

Can you try to create a function like

const ArrayLikeImages = ('yourImage1', 'yourImage2', 'yourImage3') => arguments;

and then the line

this.socialSharing.shareViaWhatsApp(null, ArrayLikeImages , null);

use the forloop in async

const imageurls = [arrayofImageLinks];
let array = [];


for (var _i = 0; _i < imageurls.length; _i++) {
    const url = imageurls[_i];

this.http.get(url, {
            responseType: ResponseContentType.Blob
          })
          .toPromise()
          .then(async (res: any) => {
            const imgBlob = new Blob([res._body], {
              type: res.headers.get("Content-Type")
            });

            var reader = new FileReader();
            reader.readAsDataURL(imgBlob);
            reader.onloadend = async () => {
              const base64data = reader.result;
              array.push(base64data);
            };
          })
          .catch(err => {
            console.log(err)
          });

}

this.socialSharing.shareViaWhatsApp("Title", "", array).then(() => {
//do something when done
}).catch(err => {
// Error Occured
console.log(err); 
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM