I am trying to share an image, either taken from camera or from gallery, to other devices through various available device's application's(eg whatsApp, skype, email etc.) I found the "Share" function provided but as per my knowledge and research, it only allows to share text data.
Has someone have any idea for sharing an image through a react native application.
Thanks in advance.
Adding Image Let us create a new folder img inside the src folder. We will add our image (myImage. png) inside this folder. We will show images on the home screen.
Solution:
Get the path of the image to convert base64.
For share image use: react-native-share lib share
To access the device directories, I recommend using: rn-fetch-blob. Wikki lib
  dwFile(file_url) {
      let imagePath = null;
      RNFetchBlob.config({
          fileCache: true
      })
      .fetch("GET", file_url)
      // the image is now dowloaded to device's storage
      .then(resp => {
          // the image path you can use it directly with Image component
          imagePath = resp.path();
          return resp.readFile("base64");
      })
      .then(async base64Data => {
          var base64Data = `data:image/png;base64,` + base64Data;
          // here's base64 encoded image
          await Share.open({ url: base64Data });
          // remove the file from storage
          return fs.unlink(imagePath);
      });
  }
Hope this helps.
You can also send the image with Share through the url parameter:
url: "data:image/png;base64,<base64_data>"
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With