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

前端 未结 15 962
情书的邮戳
情书的邮戳 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:54

    This is an old question and I guess the AWS JS SDK has changed a lot since it was asked. Here's yet another way to do it these days:

    s3.listObjects({Bucket:'mybucket', Prefix:'some-pfx'}).
    on('success', function handlePage(r) {
        //... handle page of contents r.data.Contents
    
        if(r.hasNextPage()) {
            // There's another page; handle it
            r.nextPage().on('success', handlePage).send();
        } else {
            // Finished!
        }
    }).
    on('error', function(r) {
        // Error!
    }).
    send();
    

提交回复
热议问题