Is it possible to save files with react-native inside Documents or Downloads? I am trying to save a pdf file with react-native-fs:
let file = await RNHTMLtoPDF.convert(options)
const destinationPath = RNFS.DocumentDirectoryPath "/" fileName ".pdf"
RNFS.copyFile(file.filePath, destinationPath)
but it is saved in the root directory (/data/user/0/com.prodhealth.mobile.Dev/files/TestTest_2022-02-22_2022-02-22.pdf) which is not accessible for normal users.
Is there a way to save it directly in Documents/Downloads of internal storage of the phone? I need that user can easily access this file.
CodePudding user response:
you can use react-native-fetch-blob
- cp(src:string, dest:string):Promise
dirs
This constant is a hash map containing commonly used folders:
- DocumentDir
- MainBundleDir (Can be used to access files embedded on iOS apps only)
- DownloadDir (Android Only)
Example
RNFetchBlob.fs.cp(SRC_PATH, DEST_PATH)
.then(() => { ... })
.catch(() => { ... })