• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

react-native plugin for uploading files with multipart/form-data requests

react-native-file-transfer npm version

This little plugin lets you easily upload files from your photo library to a web server using a standard multipart/form-data POST request. It does not incorporate the tranfer of photo library images data from Objective-C to JavaScript (which is slow). The request are being made directly from Objective-C.

installation

  1. npm install react-native-file-transfer;
  2. In xcode: Add RTCFileTransfer.m in Your Project > Libraries > React > Base.

how to use it

When you properly add the RCTFileTransfer.m file to your xcode project you may now use it in the js files. Example usage:

var { NativeModules } = require('react-native');
var obj = {
    uri, // either an 'assets-library' url (for files from photo library) or an image dataURL
    uploadUrl,
    fileName,
    fileKey, // (default="file") the name of the field in the POST form data under which to store the file
    mimeType,
    headers,
    data: {
        // whatever properties you wish to send in the request
        // along with the uploaded file
    }
};
NativeModules.FileTransfer.upload(obj, (err, res) => {
    // handle response
    // it is an object with 'status' and 'data' properties
    // if the file path protocol is not supported the status will be 0
    // and the request won't be made at all
});

pull-requests welcome