Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Dirs.MusicDir after upgrade from joltup #89

Closed
halaei opened this issue Dec 18, 2021 · 21 comments
Closed

Wrong Dirs.MusicDir after upgrade from joltup #89

halaei opened this issue Dec 18, 2021 · 21 comments

Comments

@halaei
Copy link

halaei commented Dec 18, 2021

The Android directory constants are changed in #2. I think the change is wrong. Apps are still allowed to save files in root directories. For example, we let our app save their audio files in /storage/emulated/0/Musics. After migration to this package, the constants are changed and files are stored in private directories, which is wrong, at least for the purpose of our application.
I wonder if you can rollback the change, or introduce new constants for the legacy paths.
Thanks.

@RonRadtke
Copy link
Owner

@omidshafai
Copy link

This issue still exists in version 0.16.2.
The value of Dirs.MusicDir in this package is "/storage/emulated/0/Android/data/com.test.app/files/Music".
While in the joltup/rn-fetch-blob package, its value is "/storage/emulated/0/Music".

@feraswfares
Copy link

@omidshafai
did you fix this problem ??

@feraswfares
Copy link

feraswfares commented Oct 9, 2022

hello @RonRadtke
fist thank you very much for maintaining this library, I really appreciate your work.

This issue still exists in version "react-native-blob-util": "^0.16.2",
"react": "17.0.1",
"react-native": "0.64.1",
android :v9 and v11

can you please fix this

@RonRadtke
Copy link
Owner

RonRadtke commented Oct 10, 2022

@feraswfares witch directory did you use?
Did you use the legacy paths as mentioned in the release notes?
@omidshafai please read the release notes directly above you comment, this should fix your problem :)

@feraswfares
Copy link

feraswfares commented Oct 10, 2022

@RonRadtke

this is how i use the path


  RNFetchBlob.config({
    fileCache:true,
    path: `${RNFetchBlob.fs.dirs.DownloadDir}/${name}`,
  })
    .fetch(
      'POST',
      url,
      {
        // Headers...
        Authorization: `Bearer ${accessToken}`,
        'Content-Type': 'application/json',
      },
      body,
    )
    .progress((received, total) => {
      Console.log('progress', received / total);
    })
    .then((res) => {
  
    })
    .catch((err) => {
   
    });

if i try to use this

RNFetchBlob.fs.dirs.LegacyDownloadDir

i will got this error
File Error: [Error: Unexpected FileStorage response file: null]

@RonRadtke
Copy link
Owner

I'll take a look later at it.
Wich device and Android are you using? On newer Android versions this path might very well be emtpy since the API is deprecated

@RonRadtke RonRadtke reopened this Oct 10, 2022
@feraswfares
Copy link

feraswfares commented Oct 10, 2022

Thank you @RonRadtke

it is not working on both

samsung galaxy edge with android version 9.0
samsung galaxy A03 with android version 11.0

@RonRadtke
Copy link
Owner

@feraswfares I changed it now back to the old implementation (not live yet).
But this will lead to an "undefined" for API >= 29 for the legacy values.
And besides the current joltup lib version is using the same methods I'm currently using so should return the same "bad" path

@feraswfares
Copy link

@RonRadtke Thank you

i use this workaround
react-native-fs for android and calling RNFS.DownloadDirectoryPath

and its work like a charm for both android 9 and android 11

@RonRadtke
Copy link
Owner

@feraswfares yeah that is for the download dir similar to my implementation. So should work fine for you.
I'm basically doing the same the lib was doing prior to merging this PR: #2

So if it worked before that on joltup it should work again.

@RonRadtke
Copy link
Owner

@feraswfares coul you test it if it works for you after I released it?
react-antive-fs is stating that only documentDir is supported currently. This would explain the behavior I'm seeing too. (I get undefined for the downloadDir with RNFS too).

@feraswfares
Copy link

@RonRadtke
yes of course i will test it

@RonRadtke
Copy link
Owner

Great thanks!
I would like to add another fix and then bring it live.
So probably tomorrow.

@feraswfares
Copy link

@RonRadtke
thanks a lot 3>

approved it is work like a charm

image

i test it on both
samsung galaxy edge with android version 9.0
samsung galaxy A03 with android version 11.0

image

@RonRadtke
Copy link
Owner

Thank you very much. I'm glad it's working as expected for you

@fenghourun
Copy link

This issue exists for RNBlobUtil.fs.DownloadDir on version 0.17.2

@RonRadtke
Copy link
Owner

Did you change to the legacy dirs? @DavFeng1

@fenghourun
Copy link

Did you change to the legacy dirs? @DavFeng1

Hey @RonRadtke thanks for the reply, I've changing to legacy dirs and it seemed to work on android >= 10 , however I'm having issues with android 9. Do I need to change the dirs I'm accessing depending on android version?

@YASH6004
Copy link

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants