-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
36 lines (29 loc) · 867 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { NativeModules, DeviceEventEmitter } from 'react-native'
const callbacks = {};
const progressCallbacks = {};
DeviceEventEmitter.addListener('fileUploadProgress', (e) => {
const uri = e.uri;
const callback = progressCallbacks[uri];
if (callback) {
callback(e.sent, e.expectedToSend);
}
});
const FileUploader = {
upload(settings, callback, progressCallback) {
const uri = settings.uri;
callbacks[uri] = callback;
progressCallbacks[uri] = progressCallback;
NativeModules.FileUploader.upload(settings, (err, res) => {
const callback = callbacks[uri];
if ( callback ) {
delete callbacks.uri;
}
callback(err, res);
const progressCallback = progressCallbacks[uri];
if (progressCallback) {
delete progressCallback.uri;
}
});
}
};
export default FileUploader