I'm using RNHTMLtoPDF from 'react-native-html-to-pdf' and I want to store to my desired location so what should I do? I have a path that is storage emulated and that path is saved in a hook but I want this pdf downloaded to be in my device storage. Any help regarding this matter would be highly appreciated
CodePudding user response:
maybe add a standard 'share' component from react-native?
https://reactnative.dev/docs/share
and the logic is when you click on pdf or whatever button you have - the share component will be opened and then you'll choose where you want to put that file(also to save it on your phone)
CodePudding user response:
You can use npm i react-native-fs
library for save in local devices
Sample Code:
import React from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
import RNFS from 'react-native-fs';
export default function App() {
//if you want to save in download directory then you can use this path
const path = RNFS.DownloadDirectoryPath;
const saveFile = () => {
RNFS.copyFile(yourCurrentFilePath, yourDestinationFilePath);
};
return (
<View style={{flex: 1}}>
<TouchableOpacity onPress={() => saveFile()}>
<Text>Save</Text>
</TouchableOpacity>
</View>
);
}
For More Information you can explore the react-native-fs library documents react-native-fs