I'm able to save .xlsx file into the phone storage but I've two issues.
App exits automatically once it saves a .xlsx file into the phone storage.
.xlsx file is saving in 'DCIM' folder, but I need to save in 'Download' folder.
handleDownload = async () => {
const data = this.handleDownloadAbleLogs();
if (!data.length)
return ToastAndroid.showWithGravity(
"Sorry, no logs available to download.",
ToastAndroid.LONG,
ToastAndroid.CENTER
);
const ws = XLSX.utils.json_to_sheet(data);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Logs");
const wbout = XLSX.write(wb, {
type: "base64",
bookType: "xlsx",
});
const uri = `${FileSystem.cacheDirectory}logs.xlsx`;
try {
await FileSystem.writeAsStringAsync(uri, wbout, {
encoding: FileSystem.EncodingType.Base64,
});
console.log(uri);
this.saveXLSXFile(uri);
alert("Logs file has been saved in DCIM folder, do check there.");
} catch (e) {
console.error(e);
}};
saveXLSXFile = async (fileUri) => {
const { status } = await MediaLibrary.requestPermissionsAsync();
if (status === "granted") {
const asset = await MediaLibrary.createAssetAsync(fileUri);
await MediaLibrary.createAlbumAsync("Download", asset, false);
} else alert("We need you permission to download this file.");
};