Я использую RNFetchBlob.fs.dirs, чтобы узнать местоположение папки Downloads, чтобы я мог загрузить туда свой файл. Но даже на устройстве rela он выдает мне местоположение, в котором находится папка с именем "emulated", и выдается ошибка, что не может найти это местоположение. Ниже приведен code. Заранее спасибо.
const response = await fetch(url, {
method,
headers,
body
});
if (!response.ok) {
throw new Error('Failed to fetch file');
}
// Get the file as a blob
const blob = await response.blob();
// Define the path where you want to save the file3
console.log("path",RNFetchBlob.fs.dirs)
const filePath = `${RNFetchBlob.fs.dirs.DownloadDir}/${fileName}`; // Change the filename and extension as needed
RNFetchBlob.config({
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
path: filePath, // The path where the file will be saved
description: 'Downloading the file',
},
});
// Save the file using RNFetchBlob
const fileReader = new FileReader();
fileReader.onloadend = () => {
const base64data = fileReader.result;
console.log({filePath})
RNFetchBlob.fs
.writeFile(filePath, base64data.split(',')[1], 'base64')
.then(() => {
console.log('File saved successfully:', filePath);
// You can now notify the user or open the file
})
.catch((error) => {
console.error('Error saving file:', error);
});
};
fileReader.readAsDataURL(blob);
Софрон
Вопрос задан1 января 2024 г.