react-native-blob-util
react-native-blob-util copied to clipboard
android LegacyDownloadDir
Hello,
Thank you for maintaining the package.
We were using ReactNativeBlobUtil.fs.dirs.DownloadDir but we figured out that it's no longer point to the Download directory in the external storage like /storage/emulated/0/Download or /storage/sdcard/Download.
But ReactNativeBlobUtil.fs.dirs.LegacyDownloadDir seems to work as intended. is LegacyDownloadDir supported in all android versions API > 21?
We just need to download files to /storage/emulated/0/Download/{APP_NAME}/ and make sure it that works flawlessly on all supported android versions > 21.
Thank you
Please update your docs, I spent a few hours on this problem, and this dir is not mentioned in your docs. Also, the File System Access API docs point to an import that is invalid (RNFetchBlob).
Great work, I don't want to sound negative but updated docs would have saved me a lot of time.
@sentry0 you could open a PR. This is open source software after all, you're asking people to do work for free.
@sentry0 you could open a PR. This is open source software after all, you're asking people to do work for free.
Thank you! A PR is always very much appreciated. At the end most of the repo maintainers, including me, are doing this in their spare time
Hello,
Thank you for maintaining the package.
We were using
ReactNativeBlobUtil.fs.dirs.DownloadDirbut we figured out that it's no longer point to theDownloaddirectory in the external storage like/storage/emulated/0/Downloador/storage/sdcard/Download.But
ReactNativeBlobUtil.fs.dirs.LegacyDownloadDirseems to work as intended. isLegacyDownloadDirsupported in all android versions API > 21?We just need to download files to
/storage/emulated/0/Download/{APP_NAME}/and make sure it that works flawlessly on all supported android versions > 21.Thank you
Yes ir should. But there are some deprecated APIs used under the hood to get the legacy folders. No way to say how long google will keep these available
i am facing this issue again in
"react-native-blob-util": "^0.19.9", "react-native": "0.73.6",
export const exportClientData = async (type: 'all' | 'single', client_id?: string) => {
let filepath = '';
let url = '';
if (type === 'all') {
url = `https://...`;
} else if (type === 'single') {
url = `https:///.......`;
}
// Get the app's cache directory
const { fs } = ReactNativeBlobUtil;
const cacheDir = Platform.OS === 'ios' ? fs.dirs.DocumentDir : fs.dirs.LegacyDownloadDir;
// Define the filename
const filename = 'filename';
// Construct the full filepath
if (type === 'all') {
filepath = `${cacheDir}/${filename}/ClientData.zip`;
} else if (type === 'single') {
filepath = `${cacheDir}/${filename}/${client_id}.zip`;
}
try {
// // Ensure the directory exists
// const dirPath = `${cacheDir}/${filename}`;
// const isDir = await fs.isDir(dirPath); // Check if the directory exists
// if (!isDir) {
// await fs.mkdir(dirPath); // Create the directory if it does not exist
// }
// Download the file and save it to the cache directory
const configOptions:any = Platform.select({
ios: {
fileCache: true,
path: filepath,
appendExt: 'zip',
},
android: {
fileCache: true,
path: filepath,
appendExt: 'zip',
},
});
const response = await ReactNativeBlobUtil.config(configOptions).fetch('GET', url, {
"Accept": "*/*",
"Accept-Encoding": "*/*",
});
console.log('response==>>', JSON.stringify(response, undefined, 4));
return response;
} catch (error) {
console.error('error in downloading==>', error);
return error;
}
};