AWS S3 SDK Get the folder instead of a file

前端 未结 2 817
一生所求
一生所求 2020-12-11 23:57

Below codes can get 1 single file from AWS 3 but, what about a folder?

var _key:int=Account.lessons[dl_i].id;
var dest:String =  Conf.Dir+_key;
var request:G         


        
2条回答
  •  孤街浪徒
    2020-12-12 00:01

    The javascript code below will count the files inside a "folder"; in fact, it will list objects sharing the same part of the name, as @Viccari pointed out there is no folder. As data.Contents will be an array containing details on "the files inside the folder", you would then "get the folder".

    var bucket  = 'the_bucket_name';
    var path_to_folder = 'path/to/the/folder/';
    var params= {Bucket: bucket, Delimiter: path_to_folder };
    s3.listObjects(params, function (err, data) {
        if (err) {
          console.log('Could not load objects from S3', err);
        } else {
            console.log('Loaded ' + data.Contents.length + ' items from S3');
        }
    });
    

    For more details, see

    • http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-examples.html where the above is coming from.
    • http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html

提交回复
热议问题