-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.js
37 lines (35 loc) · 1.15 KB
/
upload.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
37
const testFolder = './assets/';
const fs = require('fs');
let AWS = require('ibm-cos-sdk');
const config = require('./config');
let cos = new AWS.S3(config.config);
let persist = function (files) {
// let persist = function (filePath, fileName) {
let currentFile = files.pop();
return new Promise((resolve, reject) => {
console.log('Uploading file: ' + currentFile);
var request = cos.putObject
return cos.putObject({
Bucket: config.BUCKET,
Key: currentFile,
Body: fs.createReadStream('./assets/'+ currentFile),
ACL: 'public-read'
}).promise()
.then(() => {
if (files.length > 0) {
persist(files).then(() => {
console.log("Qty pending: " + files.length + "file completed: ", currentFile)
resolve(currentFile)
})
} else {
console.log("last file completed: ", currentFile)
resolve(currentFile)
}
})
.catch((err) => {
console.log(err);
reject(err)
});
});
};
persist(fs.readdirSync(testFolder))