-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudinary.js
36 lines (33 loc) · 1.09 KB
/
cloudinary.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
CloudinaryAPI = (function() {
const url = 'https://api.cloudinary.com/v1_1/dnkgfobr8/image/upload';
const preset = 'ymoszsjn';
const upload = (payload) => {
return new Promise((resolve, reject) => {
const urls = [];
let j = 0;
for (let i = 0; i < payload.length; i++) {
const data = new FormData();
data.append('file', payload[i].file, payload[i].name);
data.append('upload_preset', preset);
fetch(url, {
method: 'POST',
body: data,
}).then((res) => {
return res.text();
}).then((data) => {
data = JSON.parse(data);
urls.push(`${data.secure_url}\n`);
j += 1;
if (j === payload.length) {
resolve({ urls });
}
}).catch((err) => {
reject(err);
});
}
});
};
return {
upload: upload,
};
})();