React-native-fetch-blob downloading file

Arista Anggisavitri picture Arista Anggisavitri · Jun 20, 2017 · Viewed 17.2k times · Source

I just want my app download a file from the server by using react-native-fetch-blob. The problem is, where do the file stored? I just console.log the callback from react-native-fetch-blob and got this object

React-native-fetch-blob object callback

this is my code

alert("downloading");
RNFetchBlob
    .config({
        useDownloadManager : true, 
        fileCache : true
    })    
    .fetch('GET', 'http://fontawesome.io/assets/font-awesome-4.7.0.zip', {})
    .then((res) => {

        console.log(res);
        alert("Download");
        alert('The file saved to ', res.path());
    })

Any solution?

Answer

Ayush Raichand picture Ayush Raichand · Jun 8, 2019

function downloadFile(url,fileName) {
  const { config, fs } = RNFetchBlob;
  const downloads = fs.dirs.DownloadDir;
  return config({
    // add this option that makes response data to be stored as a file,
    // this is much more performant.
    fileCache : true,
    addAndroidDownloads : {
      useDownloadManager : true,
      notification : false,
      path:  downloads + '/' + fileName + '.pdf',
    }
  })
  .fetch('GET', url);
}

use this answer it will work for sure