forked from yortuc/react-native-cloudinary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (32 loc) · 759 Bytes
/
index.js
File metadata and controls
36 lines (32 loc) · 759 Bytes
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
var FileTransfer = require('NativeModules');
var Sha1 = require('Sha1');
module.exports = {
config: function(options) {
/*
options = {
apiSecret,
apiKey,
cloudName
}
*/
this.options = options;
},
upload: function (uri, successCb, errorCb) {
var timestamp = Date.now(),
keys = "timestamp=" + timestamp + this.options.apiSecret,
signature = Sha1.hash( keys ),
obj = {
uri: uri,
uploadUrl: "https://api.cloudinary.com/v1_1/" + this.options.cloudName + "/image/upload",
data: {
api_key: this.options.apiKey,
timestamp: timestamp,
signature: signature
}
};
FileTransfer.upload(obj, (err, res) => {
if(res) successCb(res);
if(err) errorCb(err);
});
}
};