Not listing the files using rn fetch blob in react native [Error: Attempt to get length of null array]

1.4k Views Asked by At

I was trying to list all the files in a folder using rn fetch blob in react native. When i tried to list it i am getting an error saying

[Error: Attempt to get length of null array]

here is the below code I have tried to list the files.

 try {
        var TRACK_FOLDER = RNFetchBlob.fs.dirs.DownloadDir + '/BlabberApp/';
        let files = await RNFetchBlob.fs.ls(TRACK_FOLDER)
        console.log(files);
      } catch (error) {
        console.log(error);
      }

Its working perfectly in system emulator and when i tested in real devices its force closing and throwing this error. I am pretty sure that i gave given storage permission for this but still I am getting this error.

Any help would be appreciable.

Thanks in advance :)

2

There are 2 best solutions below

0
On

Usually, this is a Storage Permission Error: You need to ask permission.

0
On

use this code ,I am using this to get the name of files in that specified folder and TRACK_FOLDER is path of the folder-

RNFetchBlob.fs.ls(TRACK_FOLDER).then(files => {
  console.log(files);
 
}).catch(error => console.log(error))