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.
npm install react-native-file-transfer
;- right click on Libraries
- select Add Files to ... option
- navigate to node_modules/react-native-file-transfer/lib/ios and add
RCTFileTransfer.xcodeproj
- on navigator click on your project name and on Target select your project name.
- Select
Build Phase
and addRCTFileTransfer.o
to yourLink Binary With Libraries
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,
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