0.1.2 • Published 3 years ago
react-native-file-asset v0.1.2
React Native File Asset
A react native package to load file from android's asset and iOS's resources
Install
npm i react-native-file-asset
Usage
- iOS: Add file to Resource folder of iOS project by Xcode
- Android: Add file to asset folder of Android project by Android Studio
- Import FileAsset as
import FileAsset from 'react-native-file-asset';
then use 2 apisloadTextFile
andloadFilePath
- To read content from file path, you can use the package
react-native-fs
Example use with loadTextFile
import FileAsset from 'react-native-file-asset';
FileAsset.loadTextFile('text', 'txt')
.then((content: string) => {
console.log(content);
})
.catch((error: Error) => {
console.log('load file error', error);
});
Example use with loadFilePath
import FileAsset from 'react-native-file-asset';
const RNFS = require('react-native-fs');
FileAsset.loadFilePath('text', 'txt')
.then(async (filePath: string) => {
const content = await RNFS.readFile(filePath, 'utf8');
console.log(content);
})
.catch((error: Error) => {
console.log('load file path error', error);
});