Home > Blockchain >  Download txt file from text in React Native
Download txt file from text in React Native

Time:05-16

I'm trying to Download txt file from a text but that function is not working fine.

Txt Function

import RNFS from 'react-native-fs';

  const txtDownload = () => {
    let path = `${RNFS.DocumentDirectoryPath}/${filename}.txt`;
    RNFS.writeFile(path, `Here is text`, 'utf8').then((res) => {
      Toast('File saved successfully');
    }
    ).catch((err) => {
      Toast(err);
    });
  }

It returns File saved successfully but I can't find file

CodePudding user response:

Log the path and check the location where it's trying to store. For me, it shows the location as below when I try to store in ${RNFS.DocumentDirectoryPath}/help.txt

/data/user/0/com.sample/files/help.txt

I suspect you were checking in the Documents folder. I don't know if you can write to the Documents folder. But it works for the Download folder using RNFS.DownloadDirectoryPath.

  • Related