2

I have used the react-native-fs library to download image through my app. The download shows to be completed but still the image doesn't show up in the phone anywhere. The folder shows the modified date but no image over there.

The function that I am calling :

RNFS.downloadFile({ fromUrl: 'https://facebook.github.io/react-native/img/header_logo.png', toFile: '${RNFS.DocumentDirectoryPath}/react-native-hello.png', }).promise.then((r) => { console.log("download done"); this.setState({ isDone: true }) });

Can anyone help me get though this ?

Sourabh Banka
  • 1,080
  • 3
  • 24
  • 48
  • After download check the response first and then the file exist or not ------ if(r.statusCode==200){ RNFS.exists('react-native-hello.png').then((exists)=>{ console.log('File exists::'); }) – Pramod Dec 19 '18 at 07:31

1 Answers1

0
  Try this code:



  actualDownload = () => {
      let url = 'https://facebook.github.io/react-native/img/header_logo.png'
      let name = 'logo.png'
      let dirs = RNFS.DocumentDirectoryPath/MyApp;
      console.log("--path--",dirs)
      const file_path = dirs +'/'+name

      RNFS.readFile(url, 'base64')
      .then(res =>{
        this.setState({resBase64:res})
        let base64 = this.state.resBase64
        RNFS.writeFile(file_path,base64,'base64')
        .catch((error) => {
          console.log("err",error);
        });
      });
    }