import RNFetchBlob from 'rn-fetch-blob'
// code for component
const toast = useToast();
const downloadCSV = async () => {
if (loading) return;
setLoading(true)
const { fs } = RNFetchBlob;
let downloadsDir = fs.dirs?.DownloadDir; // Directory where downloaded files are saved
const fileUrl = 'https://filename'; // URL of the CSV file
const fileName = 'Sample-Data-' + Date.now() + '.csv'; // Name to save the file with
// Config for the download
const configOptions = {
trusty: true,
session: "test",
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
path: `${downloadsDir}/${fileName}`,
// description: 'Downloading CSV file.',
},
};
// Trigger the download
let res = await RNFetchBlob.config(configOptions).fetch('GET', fileUrl);
if (res) {
toast.show({ title: "Download successfully !" });
setTimeout(() => {
setLoading(false);
}, 500)
}
};
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)