ListObjectsAsync() public method

Initiates the asynchronous execution of the ListObjects operation.
public ListObjectsAsync ( ListObjectsRequest request, System cancellationToken = default(CancellationToken) ) : Task
request ListObjectsRequest Container for the necessary parameters to execute the ListObjects operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
return Task
        public async Task<IList<S3Object>> GetListofFiles()
        {
           
               
                BasicAWSCredentials credentials = new BasicAWSCredentials("AKIAJTADDHY7T7GZXX5Q", "n4xV5B25mt7e6br84H2G9SXBx8eDYTQJgCxoaF49");
                AmazonS3Client s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);
                string token = null;
                var result = new List<S3Object>();
                do
                {
                    ListObjectsRequest request = new ListObjectsRequest()
                    {
                        BucketName = ExistingBucketName    
                    };
                    ListObjectsResponse response = await s3Client.ListObjectsAsync(request).ConfigureAwait(false);
                    result.AddRange(response.S3Objects);
                    token = response.NextMarker;

                } while (token != null);              
                
             return result;
            
            
        }
示例#2
0
        public static List<S3Object> ListObjectsHelper(AmazonS3Client client, string bucketName)
        {
            AutoResetEvent ars = new AutoResetEvent(false);
            Exception responseException = new Exception();
            List<S3Object> s3Objects = null;
            client.ListObjectsAsync(new ListObjectsRequest()
            {
                BucketName = bucketName
            }, (response) =>
            {
                responseException = response.Exception;
                if (responseException == null)
                {
                    s3Objects = response.Response.S3Objects;
                }
                ars.Set();
            }, new AsyncOptions { ExecuteCallbackOnMainThread = false });

            ars.WaitOne();
            if (responseException != null)
            {
                throw responseException;
            }
            return s3Objects;
        }