3

I am working on react native share. Now i can share image with title and message. While i am sharing the image it's little slow. So I am thinking that i need to optimize the image file size. So how to do that in react native. I am using react-native-fetch-blob

Here is my working code. How do i optimize with this code.

Thanks in advance

_downloadImageAndShare(url ,title, message) {
    const { fs } = RNFetchBlob.fs;
    const self = this;

    let filePath = null;

    RNFetchBlob.config({ fileCache: true })
      .fetch('GET', url)
      .then(resp => resp.readFile('base64')
          .then(base64 => ({ resp, base64 })))
      .then(obj => {
        filePath = obj.resp.path();
        const headers = obj.resp.respInfo.headers;
        const type = headers['Content-Type'];
        const dataUrl = 'data:' + type + ';base64,' + obj.base64;
        RNFetchBlob.fs.unlink(filePath)
        return { url: dataUrl, title, message };

      })
      .then(options => Share.open(options)).catch(err => {err && console.log(err); })         
   }
khalifathul
  • 558
  • 1
  • 10
  • 24

0 Answers0