0

I am using RNFetchBlob to share image as base64 format. But the image is downloading in my local folder. I want to delete it. By my research knowledge i want to unlink the image path. I don't know how to do that. Here is my code

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

  })
  .then(options => Share.open(options)).catch(err => {err && 
  console.log(err); })         
}

how to use this code inside this method

RNFetchBlob.fs.unlink(path)
.then(() => { ... })
.catch((err) => { ... })

and how to specify the unlink(path) ??

thanks in advance.

khalifathul
  • 558
  • 1
  • 10
  • 24

1 Answers1

1

You can specify file location with config with path param.

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

  })
  .then(options => Share.open(options)).catch(err => {err && 
  console.log(err); })         
}

Then you can call unlink like this

RNFetchBlob.fs.unlink(filePath)
.then(() => { ... })
.catch((err) => { ... })
Harikrishnan
  • 9,688
  • 11
  • 84
  • 127