6

I have a folder of Images in my project

I'm struggling to access an image like this ProjectRoot/App/Images/image.png

in iOS I can access it by using:

RNFetchBlob.fs.dirs.MainBundleDir + 'assets/App/Images/image.png'

What would be the Android way? I've tried DocumentDir and MainBundleDir, I've only had a "file doesn't exist" returned

I have tried RNFetchBlob.fs.asset('image.png') and RNFetchBlob.fs.asset('path/to/image.png') and haven't been successful

I've logged out all the files and directories that I have access to and unfortunately I cannot find it

Need some help.

It is suggested that you can add

aaptOptions, noCompress to prevent assets in the Android assets folder from compressing into the bundle, however they exit outside of the Android project folder structure

"react-native": "0.49.1", "react-native-fetch-blob": "0.10.8",

Android: buildToolsVersion "23.0.1" targetSdkVersion 23

1 Answers1

1

I solved it in my instance.

Basically, and unfortunately, you need to duplicate the assets into your Android asset folder

e.g.

ProjectRoot/App/Images/image.jpg

must be copied to

ProjectRoot/android/app/src/main/assets/image.jpg

(subfolders can be used if needed)

rerun your packager and then the files are accessible by

RNFetchBlob.fs.asset("image.jpg")
  • Can you substitute the PATH string required by e.g. `copyFile` or `appendFile` with that? Or do you need to use `RNFetchBlob.wrap(RNFetchBlob.fs.asset('my-asset.png')))`? Or how does that work? – David Schumann Aug 30 '18 at 12:26