DeleteObjectsAsync() public method

Initiates the asynchronous execution of the DeleteObjects operation.
public DeleteObjectsAsync ( DeleteObjectsRequest request, System cancellationToken = default(CancellationToken) ) : Task
request Amazon.S3.Model.DeleteObjectsRequest Container for the necessary parameters to execute the DeleteObjects operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
return Task
示例#1
0
 public static void DeleteObjectHelper(AmazonS3Client client, string bucketName, string key, string versionId = null)
 {
     Exception responseException = null;
     AutoResetEvent ars = new AutoResetEvent(false);
     client.DeleteObjectsAsync(new DeleteObjectsRequest()
     {
         BucketName = bucketName,
         Objects = new List<KeyVersion> { new KeyVersion() { Key = key, VersionId = versionId } }
     }, (response) =>
     {
         responseException = response.Exception;
         ars.Set();
     }, new AsyncOptions { ExecuteCallbackOnMainThread = false });
     ars.WaitOne();
     Assert.IsNull(responseException);
 }
示例#2
0
        async Task EmptyBucket(Amazon.S3.AmazonS3Client client, string BucketName)
        {
            int itemCount = 0;
            var logger    = LogManager.GetCurrentClassLogger();

            do
            {
                var listObjectsResult = await client.ListObjectsV2Async(new ListObjectsV2Request { BucketName = BucketName });

                itemCount = listObjectsResult.KeyCount;

                if (itemCount > 0)
                {
                    var deleteObjectsResult = await client.DeleteObjectsAsync(new DeleteObjectsRequest { BucketName = BucketName, Objects = listObjectsResult.S3Objects.Select(a => new KeyVersion {
                            Key = a.Key, VersionId = null
                        }).ToList() });

                    if (deleteObjectsResult.HttpStatusCode == System.Net.HttpStatusCode.OK)
                    {
                        logger.Debug($"Successfully deleted {deleteObjectsResult.DeletedObjects.Count} objects from bucket {BucketName}.");
                    }
                }
            } while (itemCount > 0);
        }