Listing files in a specific “folder” of a AWS S3 bucket

前端 未结 7 621
耶瑟儿~
耶瑟儿~ 2020-12-24 04:51

I need to list all files contained in a certain folder contained in my S3 bucket.

The folder structure is the following

/my-bucket/users/

        
相关标签:
7条回答
  • 2020-12-24 05:30

    If your goal is only to take the files and not the folder, the approach I made was to use the file size as a filter. This property is the current size of the file hosted by AWS. All the folders return 0 in that property. The following is a C# code using linq but it shouldn't be hard to translate to Java.

    var amazonClient = new AmazonS3Client(key, secretKey, region);
    var listObjectsRequest= new ListObjectsRequest
                {
                    BucketName = 'someBucketName',
                    Delimiter = 'someDelimiter',
                    Prefix = 'somePrefix'
                };
    var objects = amazonClient.ListObjects(listObjectsRequest);
    var objectsInFolder = objects.S3Objects.Where(file => file.Size > 0).ToList();
    
    0 讨论(0)
提交回复
热议问题