Dapatkan semua objek dari S3 Bucket NodeJs

function s3Client() {
    // if code in local development the use local s3 
    let option = {
       
        region: '',
        apiVersion: '2006-03-01',

        httpOptions: {
            connectTimeout: 5000,
            timeout: 120000
          },
        maxRetries: 2,
    }  
 
    option['credentials'] = {
        accessKeyId: '',
        secretAccessKey: ''
        
    }
    //option['endpoint'] = ''
    //option['s3ForcePathStyle'] = true

    return new AWS.S3(option);
}

var AWS = require('aws-sdk');
var s3 = s3Client();

var params = {
    Bucket: ""
   };


function test(params) {
    s3.listObjectsV2(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else {
            // console.log(data);
            if(data.IsTruncated) {
                console.log(data.Contents.length);
                if(data.NextContinuationToken){
                    params.ContinuationToken = data.NextContinuationToken;
                    test(params);
                }
            }
            else {
                console.log(data.Contents.length);
            }

        }  
    }); 
}


test(params);



Light Lark