react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

android LegacyDownloadDir

Open HasanAlyazidi opened this issue 2 years ago • 5 comments

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

HasanAlyazidi avatar Sep 12 '23 16:09 HasanAlyazidi

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 avatar Oct 02 '23 23:10 sentry0

@sentry0 you could open a PR. This is open source software after all, you're asking people to do work for free.

rcidt avatar Jan 12 '24 18:01 rcidt

@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

RonRadtke avatar Jan 12 '24 20:01 RonRadtke

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

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

RonRadtke avatar Jan 12 '24 20:01 RonRadtke

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;
  }
};


YASH6004 avatar May 21 '24 13:05 YASH6004