Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

Want to share multiple images with separate caption to each image Whatsapp, react native share

I am using React Native Share library, a good one, I just need little help,

It is sharing multiple images with same caption,

i just want to share multiple images with separate message (caption) to each image,

suppose, if there is 5 images, then caption to 5 images is different not same.

In current situation, it share 5 images with same message (caption)

Here is my code

var imgs=["base64IMAGE1...///","base64IMAGE2..///","base64IMAGE3..///"]; let shareImage = { title:"title", message:"this is message need to send separate to each image", urls:abcc, subject: "Image" }; Share.open(shareImage).catch(err => console.log(err));

I have attached current situation screenshots..

image 1 on whatsapp image 2 on whatsapp

all sent with same caption, i just to send multiple images with separate messages

ThankYou.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've created working example to share multiple or single images using react-native-share

CheckOut ExpoSnack Here

ReactNativeShareImage

added comments before every method what it'll do and what needs to be replaced.

// multiple images share example
const shareMultipleImages = async () => {
    const shareOptions = {
        title: 'Share multiple files example',
        // here replace base64 data with your local filepath
        // base64 with mimeType or path to local file
        urls: [base64ImagesData.image1, base64ImagesData.image2],
        failOnCancel: false,
    };

    // If you want, you can use a try catch, to parse
    // the share response. If the user cancels, etc.
    try {
        const ShareResponse = await Share.open(shareOptions);
        setResult(JSON.stringify(ShareResponse, null, 2));
    } catch (error) {
        console.log('Error =>', error);
        setResult('error: '.concat(getErrorString(error)));
    }
};

you can add local file path in shareMultipleImage method like this

urls: Array of base64 string you want to share. base64 with mimeType or path to local file (Array[string])

React Native Share Docs

const shareOptions = {
    title: 'Share multiple files example',
    urls: ["file..///","file..///","file..///"],
    failOnCancel: false,
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...