0.1.2 • Published 3 years ago

react-native-file-asset v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Native File Asset

version licence

A react native package to load file from android's asset and iOS's resources

Install

npm i react-native-file-asset

Usage

  1. iOS: Add file to Resource folder of iOS project by Xcode
  2. Android: Add file to asset folder of Android project by Android Studio
  3. Import FileAsset as import FileAsset from 'react-native-file-asset'; then use 2 apis loadTextFile and loadFilePath
  4. 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);
  });

License

MIT