AWS S3 SDK Get the folder instead of a file

前端 未结 2 703
一生所求
一生所求 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
    0 讨论(0)
  • 2020-12-12 00:16

    There is no such stuff as folders in Amazon S3. It is a "flat" file system. The closer you can get to folders is adding prefixes like foo/bar/filename.txt to your file names. Even though several S3 tools will show you stuff as if they were contained inside folders, this concept does not exist on S3.

    Please see this related thread: Amazon s3 Folders Problem

    0 讨论(0)
提交回复
热议问题