joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 772 forks source link

downloaded files aren't valid to read #564

Open hamzamekk opened 4 years ago

hamzamekk commented 4 years ago

hello guys i am working with react native project i need to download some files from a server i am using this package and it show me that the download passed but i dont think it download the file from server it give me a link of a file and when i check it it has only 35 kb and can't be opened and if i use download manager it give me this error [Error: Download manager failed to download from 'my url' Code = 16] here is my code

 let url = '/api/v1/files/5e6f856288b03d4ba3d9f6c2/download';
    RNFetchBlob.config({
      fileCache: true,
      appendExt: 'pdf',
      addAndroidDownloads: {
        notification: true,
        title: 'working',
        description: 'client bt',
        mime: 'application/pdf',
        // Make the file scannable  by media scanner
        // mediaScannable : true,
      },
    })
      .fetch('GET', `${url_base}${url}`, {})
      .then(resp => {
        // the path of downloaded file
        // console.log( resp.info())
          console.log(resp.path());
        } 
      })
      .catch(err => {
        console.log('download error', err);
      });

i am using "react": "16.9.0", "react-native": "0.61.5", "rn-fetch-blob": "^0.12.0",

paulrevival commented 4 years ago

I think u have to set a path to your config-object, where your file would be saved to:

const pathToSave = RNFetchBlob.fs.dirs.DownloadDir; // or any other dir of .dirs
RNFetchBlob.config({
  path: pathToSave,
  // other options here...
})...

But I wonder if u will have another issue like my one: #567