react-native-file-transfer-android-plus

0.0.3 • Public • Published

react-native-image-upload-android-plus

Upload images or files through a multipart/form-data request

This is an upgrade version of react-native-image-upload-android with 'data' parameter implementation.

Installation

npm install react-native-file-transfer-android

Add to your settings.gradle:

include ':RNFileTransfer', ':app'
project(':RNFileTransfer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-file-transfer-android/android')

Add to your android/build.gradle:

dependencies {
  ...
  compile project(':RNFileTransfer')
}

Add to MainActivity.java

import com.burlap.filetransfer.FileTransferPackage;
...
mReactInstanceManager = ReactInstanceManager.builder()
        .setApplication(getApplication())
        .setBundleAssetName("index.android.bundle")
        .setJSMainModuleName("index.android")
        .addPackage(new MainReactPackage())
        .addPackage(new FileTransferPackage())

Usage:

var FileTransfer = require('react-native-file-transfer-android');
FileTransfer.upload({
  uri: uri,
  uploadUrl: 'http://example.com/upload',
  fileName: 'temp.jpg',
  mimeType: 'image/jpg',
  headers: {
    'Accept': 'application/json'
  },
  data: {
    
  }
}, (err, res) => {
  if(err) {
    console.error(err);
  } else {
    console.log(res);
  }
});

Options

  • uri - uri of the file in the android filesystem
  • uploadUrl - endpoint to upload the file to (uses POST)
  • fileName - name of the file
  • mimeType - file type
  • headers - map of headers
  • data - any extra data you want sent to the server

Package Sidebar

Install

npm i react-native-file-transfer-android-plus

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • ds3783_npm