-
-
Save jpfong/7aa64cf0d0c38fc43adeda56106020b3 to your computer and use it in GitHub Desktop.
var aws = require('aws-sdk'); | |
var s3 = new aws.S3(); | |
var params = { | |
Bucket: 'node-sdk-sample-7271', | |
Delete: { // required | |
Objects: [ // required | |
{ | |
Key: 'foo.jpg' // required, if in a directory: 'directory_name/file.ext' | |
}, | |
{ | |
Key: 'sample-image--10.jpg' | |
} | |
], | |
}, | |
}; | |
s3.deleteObjects(params, function(err, data) { | |
if (err) console.log(err); // an error occurred | |
else console.log(data); // successful response | |
}); |
Thanks, how do you bulk delete folders and its parent folders.
Should it be first sorted descending by creation date and then delete
To delete the top most parent folder at last after deleting all the childs first?
Example
{
"Key": "clients/C1/sites/G100/camear/MP4_H264-1660554009-1660554309 - Copy (2) - Copy.mp4"
},
{
"Key": "clients/C1/sites/G100/camear/MP4_H264-1660554009-1660554309 - Copy (2).mp4"
},
{
"Key": "clients/C1/sites/G100/camear/"
},
{
"Key": "clients/C1/sites/G100/siteInfo"
},
{
"Key": "clients/C1/sites/G100/"
}
I am still getting thiserror ... any idea?
2022-10-28T13:19:04.637Z aa2b24fd-23a9-4604-a793-8e266ab528ed INFO 500: null
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/services/s3.js:710:35)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:686:14)
at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:688:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
code: 500,
region: null,
time: 2022-10-28T13:19:04.636Z,
requestId: null,
extendedRequestId: undefined,
cfId: undefined,
statusCode: 500,
retryable: true
}
My delete request is something like this..
deleteObjectsRequest :
{
"Bucket": "lessonvugw",
"Delete": {
"Objects": [
{
"Key": "clients/C1/sites/G100/camear/MP4_H264-1660553709-1660554009 - Copy.mp4"
}
]
}
}
❤️