react-native-fetch-blobreact-native-fs

'react-native-fs' and 'react-native-fetch-blob' can not find the downloaded file


I user 'react-native-fs' and 'react-native-fetch-blob' to test file download in android emulator, the console show me that the download is success, but I can not find where the file is in my emulator file system,or maybe it did not download successfully,can anybody tell me what to do,thanks


Solution

  • Use this function for Android with react-native-fetch-blob.

    It works for me and the downloaded file will be placed in the downloads directory of the device/emulator.

    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);
    }