当我试图下载文件时.它不是存储在路径/data/data/[Application Package name folder]/files中,而是在/storage/emulated/0/Android/data/[Application Package name folder]/files中下载.
我试过使用rn-fetch-blob套餐和react-native-blob-util套餐.我收到的错误是不受支持的路径.作为参考,我附上了错误屏幕截图
Below is the code I have written for download个
const downloadRecord = async () => {
let FILE_URL = `https://www.africau.edu/images/default/sample.pdf`;
let file_ext = getFileExtention(FILE_URL);
file_ext = "." + file_ext[0];
let extension = file_ext;
let date = new Date();
let Name = bookID; // + Math.floor(date.getTime() + date.getSeconds() / 2);
try {
const { config, fs } = ReactNativeBlobUtil;
const DownloadDir =
Platform.OS == "ios"
? `${fs.dirs.LibraryDir}/name/`
: `${fs.dirs.DownloadDir}/name/`;
let fileName = Name + extension;
let pdfPath = DownloadDir + fileName;
console.log("Path", pdfPath);
let options = {
fileCache: true,
addAndroidDownloads: {
//Related to the Android only
useDownloadManager: true,
notification: true,
path: pdfPath,
description: "downloading...",
},
path: pdfPath,
};
//console.log(FILE_URL)
config(options)
.fetch("GET", FILE_URL)
.progress((received, total) => {
console.log("progress method", (received / total) * 100);
})
.then((res) => {
//console.log('res -> ', JSON.stringify(res));
})
.catch((error) => {
Toast.show("Error downloading Training Record.");
});
} catch (error) {}
};