-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.js
35 lines (33 loc) · 906 Bytes
/
delete.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
const testFolder = './assets/';
const fs = require('fs');
const config = require('./config');
let AWS = require('ibm-cos-sdk');
let cos = new AWS.S3(config.config);
var params = {
Bucket: config.BUCKET,
};
cos.listObjects(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
let objects = [];
data.Contents.forEach(element => {
let object = {
Key: element.Key
};
objects.push(object)
});
let deleteObject = {
Objects: objects
}
//console.log(deleteObject);
//Delete
var params2 = {
Bucket: config.BUCKET,
Delete: deleteObject
};
cos.deleteObjects(params2, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log('All files were deleted'); // successful response
});
}
});