A module support upload file to server. Support add header, multipart-form
var {FileUploader} = require('react-native-file-uploader');
let header = {
}
//Optional
FileUploader.setHeaders(headers)
let params = {
param1: ...,
param2: ...
}
let fileUpload = {
name: 'field_upload',
filepath: 'path or uri of file'
}
FileUploader.upload(url, params, fileUpload, function(error, data){
if (!error) {
console.log("Login data: ", data);
} else {
console.log("Error: ", error);
}
})
- Run in your project:
$ npm i -S https://github.com/leonacky/react-native-file-uploader.git
Comming soon
-
In
android/setting.gradle
... include ':react-native-file-uploader' project(':react-native-file-uploader').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-file-uploader/android')
-
In
android/app/build.gradle
... dependencies { ... compile project(':react-native-file-uploader') }
-
Register module (in MainApplication.java)
import com.aotasoft.rnfileuploader.FileUploaderPackage; // <--- import public class MainApplication extends Application implements ReactApplication { ...... @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new VectorIconsPackage(), new OrientationPackage(this), new FileUploaderPackage() // <--- Add here! ); } ...... }