How to list _all_ objects in Amazon S3 bucket?

前端 未结 4 1358
旧巷少年郎
旧巷少年郎 2021-02-06 23:19

S3Client.ListObjects return only 1000 of objects. How to retrieve list of all existing objects using Amazon C# library?

4条回答
  •  太阳男子
    2021-02-06 23:54

    Be aware that the answer above is not using the recommended API to List Objects: http://docs.aws.amazon.com/AmazonS3/latest/API/v2-RESTBucketGET.html

    The following snippet shows how it looks with the new API:

    using (var s3Client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1))
    {
        ListObjectsV2Request request = new ListObjectsV2Request
        {
              BucketName = bucketName,
              MaxKeys = 10
        };
        ListObjectsV2Response response;
        do
        {
             response = await s3Client.ListObjectsV2Async(request);
    
             // Process response.
             // ...
    
             request.ContinuationToken = response.NextContinuationToken;
    
        } while (response.IsTruncated);        
    }
    

提交回复
热议问题