Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Is there any way to check if the file exists in android_asset folder or not?

I need to check file existence in the folder like this:

file:///android_asset/contents/my.html

I've tried to use react-native-filesystem plugin

componentWillMount () {
    async function checkIfFileExists() {
      const fileExists = await FileSystem.fileExists('file:///android_asset/contents/my.html')
      console.log(`file exists: ${fileExists}`)
    }
}

I'm sure that my.html file is there, but I get false in fileExists. Does anybody know how to check it properly?

like image 782
Dmitry Avatar asked Apr 18 '17 11:04

Dmitry


1 Answers

Try using react-native-fs.

Looks like they have a function to just what you're looking for: https://github.com/johanneslumpe/react-native-fs#existsassetsfilepath-string-promiseboolean

like image 72
Jason Gaare Avatar answered Nov 20 '22 03:11

Jason Gaare