Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list files in assets folder react-native

I created a folder with some subfolders in android/app/src/main/assets/. I re-compiled the app and I am trying to get a list of the folder/files I put in there. However, whenever I run one of the following commands (from react-native-fetch-blob)

RNFetchBlob.fs.ls(RNFetchBlob.wrap(RNFetchBlob.fs.asset('subfolder/')))

or

RNFetchBlob.fs.ls("bundle-assets://")

or

RNFetchBlob.fs.ls(RNFetchBlob.fs.asset('subfolder/'))

I get

Error: ls error: failed to list path RNFetchBlob-file://bundle-assets://subfolder/ for it is not exist or it is not a folder at http://localhost:8081/index.android.b...

At least the assets folder should exist? How do I access the files in assets? Is there a way to do it without react-native-fetch-blob by simply passing a Path?

like image 421
Stophface Avatar asked Nov 20 '17 11:11

Stophface


People also ask

How do you access the file from assets folder in react-native?

There is readFileAssets is a method in react-native-fs. Place your file in android\app\src\main\assets . If there is no assets folder then just create it.


1 Answers

react-native-fs package has that capability from the looks of it. haven't used it. wish react-native-fetch-blob supported it, but nothing in their docs.

https://github.com/itinance/react-native-fs#readdirassetsdirpath-string-promisereaddiritem

like image 91
Anusha Dharmasena Avatar answered Sep 22 '22 08:09

Anusha Dharmasena