public async Task DeleteAsync(string[] names) { #region Preconditions if (names == null) { throw new ArgumentNullException(nameof(names)); } #endregion var batch = new DeleteBatch(names); var request = new BatchDeleteRequest(client.Host, bucketName, batch); var result = await client.DeleteObjectsAsync(request).ConfigureAwait(false); if (result.HasErrors) { throw new Exception(result.Errors[0].Message); } if (result.Deleted.Length != names.Length) { throw new Exception("Deleted count not equal to keys.Count"); } }
public BatchDeleteRequest(AwsRegion region, string bucketName, DeleteBatch batch) : base(HttpMethod.Post, region, bucketName, "?delete") { var xmlText = batch.ToXmlString(); Content = new StringContent(xmlText, Encoding.UTF8, "text/xml"); Content.Headers.ContentMD5 = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(xmlText)); CompletionOption = HttpCompletionOption.ResponseContentRead; }
public DeleteObjectBatchRequest(string host, string bucketName, DeleteBatch batch) : base(HttpMethod.Post, host, bucketName, null, "?delete") { string xmlText = batch.ToXmlString(); byte[] data = Encoding.UTF8.GetBytes(xmlText); Content = new ByteArrayContent(data) { Headers = { { "Content-Type", "text/xml" } } }; using MD5 md5 = MD5.Create(); Content.Headers.ContentMD5 = md5.ComputeHash(data); CompletionOption = HttpCompletionOption.ResponseContentRead; }
public async Task DeleteAsync(string[] keys) { var batch = new DeleteBatch(keys); var request = new BatchDeleteRequest(client.Host, bucketName, batch); var result = await client.DeleteObjectsAsync(request).ConfigureAwait(false); if (result.HasErrors) { throw new Exception(result.Errors[0].Message); } if (result.Deleted.Length != keys.Length) { throw new Exception("Deleted count not equal to keys.Count"); } }
public async Task <DeleteResult> DeleteAsync(IReadOnlyList <string> keys) { var batch = new DeleteBatch(keys); var request = new DeleteObjectBatchRequest(client.Host, bucketName, batch); var result = await client.DeleteObjectsAsync(request).ConfigureAwait(false); if (result.HasErrors) { throw new Exception(result.Errors[0].Message); } if (result.Deleted.Length != keys.Count) { throw new Exception($"Only {result.Deleted.Length} of {keys.Count} were deleted."); } return(result); }
public BatchDeleteRequest(string host, string bucketName, DeleteBatch batch) : base(HttpMethod.Post, host, bucketName, "?delete") { #region Preconditions if (batch == null) { throw new ArgumentNullException(nameof(batch)); } #endregion var xmlText = batch.ToXmlString(); Content = new StringContent(xmlText, Encoding.UTF8, "text/xml"); Content.Headers.ContentMD5 = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(xmlText)); CompletionOption = HttpCompletionOption.ResponseContentRead; }