How to read file from assets folder in react-native?

Viewed 7770

I have some data in android\app\src\main\assets and I am using rn-fetch-blob as filesystem.

But what is the schema path to assets folder in android? How to read data from it?

Is there any other way to ship pre pupolate data file in react-native ? Can I place file in react-native project root directory?

2 Answers

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.

import fs from "react-native-fs";

fs.readFileAssets("folder/file", "base64") // 'base64' for binary 
  .then(binary => {
    // work with it
  })
  .catch(console.error)

Note: Path must be relative. If android\app\src\main\assets\folder\file then use folder\file

let path = RNFetchBlob.fs.asset('my-asset.jpg')

RNFetchBlob.fs.asset('bundle-assets://my-asset.jpg');

There is a method in doc assetfilenamestrings

Related