Node.js & Amazon S3: How to iterate through all files in a bucket?

前端 未结 15 1002
情书的邮戳
情书的邮戳 2020-12-02 14:17

Is there any Amazon S3 client library for Node.js that allows listing of all files in S3 bucket?

The most known aws2js and knox don\'t seem to have this functionalit

15条回答
  •  猫巷女王i
    2020-12-02 14:44

    The cleanest way to do it for me was through execution of s3cmd from my node script like this (The example here is to delete files recursively):

    var exec = require('child_process').exec;
    var child;
    var bucket = "myBucket";
    var prefix = "myPrefix"; // this parameter is optional
    var command = "s3cmd del -r s3://" + bucket + "/" + prefix;
    child = exec(command, {maxBuffer: 5000 * 1024}, function (error, stdout, stderr) { // the maxBuffer is here to avoid the maxBuffer node process error
                console.log('stdout: ' + stdout);
                if (error !== null) {
                    console.log('exec error: ' + error);
                }
            });
    

提交回复
热议问题