🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

react-native-file-utils

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-file-utils

A utils component for React Native File operations.

latest
Source
npmnpm
Version
0.3.2
Version published
Maintainers
1
Created
Source

react-native-file-utils

Helper utils for common problems.

Utils:

  • getPathFromURI : Convert Uri to real device path for Android
  • Known paths for Android:
    • PicturesDirectoryPath : Internal pictures directory
    • DownloadsDirectoryPath : Internal downloads directory
    • DCIMDirectoryPath : Internal DCIM directory
    • CachesDirectoryPath : Application cache directory
    • FilesDirectoryPath : Application files directory

Installation (Android)

npm i react-native-file-utils --save

Linking

react-native link react-native-file-utils

OR

  • android/settings.gradle
...
include ':react-native-file-utils'
project(':react-native-file-utils').projectDir = new File(settingsDir, '../node_modules/react-native-file-utils/android')
  • android/app/build.gradle
...
dependencies {
    ...
    compile project(':react-native-file-utils')
}
  • register module (in MainActivity.java)
import com.anumang.rnfileutils.RNFUPackage; // <------- add package

public class MainActivity extends ReactActivity {
   // ...
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(), // <---- add comma
        new RNFUPackage() // <---------- add package
      );
    }

Example usage (Android only)

// require the module
var RNFU = require('react-native-file-utils');

RNFU.getPathFromURI(uriString).then(filePath =>
  console.log(filePath)
)

Use Case - get images from CameraRoll as base64

  • Required: react-native-fs https://github.com/johanneslumpe/react-native-fs
RNFU.getPathFromURI(imageUri).then(path =>
  RNFS.readFile(path, 'base64').then(imageBase64 =>
    console.log(imageBase64)
  )
)

Use Case - create images on DCIM directory as base64

let filePath = RNFU.DCIMDirectoryPath + fileName;
RNFU.writeFile(filePath, base64Content, 'base64').then(path =>
  RNFS.readFile(path, 'base64').then(imageBase64 =>
    console.log(imageBase64)
  )
)

Keywords

react-native

FAQs

Package last updated on 03 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts