本文整理汇总了C#中Amazon.S3.AmazonS3Client.DeleteObjects方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.DeleteObjects方法的具体用法?C# AmazonS3Client.DeleteObjects怎么用?C# AmazonS3Client.DeleteObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.AmazonS3Client
的用法示例。
在下文中一共展示了AmazonS3Client.DeleteObjects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteObjectList
/// <summary>AWS S3 여러 객체 삭제</summary>
public DeleteObjectsResponse DeleteObjectList(List<string> pKeyList)
{
try
{
using (AmazonS3Client client = new AmazonS3Client())
{
DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest();
multiObjectDeleteRequest.BucketName = strAwsBucketName;
foreach (string key in pKeyList)
{
multiObjectDeleteRequest.AddKey(key);
}
DeleteObjectsResponse response = client.DeleteObjects(multiObjectDeleteRequest);
//response.DeleteErrors.Count = 실패한 삭제 객체
//response.DeletedObjects.Count = 성공한 삭제 객체
//.Key, .Code, .Message로 정보 확인 가능.
return response;
}
}
catch (AmazonS3Exception amazonS3Exception)
{
throw amazonS3Exception;
}
}
示例2: DeleteBucket
public virtual void DeleteBucket(AmazonS3Client s3Client, string bucketName)
{
// First, try to delete the bucket.
var deleteBucketRequest = new DeleteBucketRequest
{
BucketName = bucketName
};
try
{
s3Client.DeleteBucket(deleteBucketRequest);
// If we get here, no error was generated so we'll assume the bucket was deleted and return.
return;
}
catch (AmazonS3Exception ex)
{
if (!ex.ErrorCode.Equals("BucketNotEmpty"))
{
// We got an unanticipated error. Just rethrow.
throw;
}
}
// If we got here, then our bucket isn't empty so we need to delete the items in it first.
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest {BucketName = bucketName};
foreach (S3Object obj in s3Client.ListObjects(new ListObjectsRequest {BucketName = bucketName}).S3Objects)
{
// Add keys for the objects to the delete request
deleteObjectsRequest.AddKey(obj.Key, null);
}
// Submit the request
s3Client.DeleteObjects(deleteObjectsRequest);
// The bucket is empty now, so delete the bucket.
s3Client.DeleteBucket(deleteBucketRequest);
}
示例3: ObjectSamples
//.........这里部分代码省略.........
// Put object
PutObjectResponse response = client.PutObject(request);
}
#endregion
}
{
#region DeleteObject Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Create a DeleteObject request
DeleteObjectRequest request = new DeleteObjectRequest
{
BucketName = "SampleBucket",
Key = "Item1"
};
// Issue request
client.DeleteObject(request);
#endregion
}
{
#region DeleteObjects Sample
// Create a client
AmazonS3Client client = new AmazonS3Client();
// Create a DeleteObject request
DeleteObjectsRequest request = new DeleteObjectsRequest
{
BucketName = "SampleBucket",
Objects = new List<KeyVersion>
{
new KeyVersion() {Key = "Item1"},
// Versioned item
new KeyVersion() { Key = "Item2", VersionId = "Rej8CiBxcZKVK81cLr39j27Y5FVXghDK", },
// Item in subdirectory
new KeyVersion() { Key = "Logs/error.txt"}
}
};
try
{
// Issue request
DeleteObjectsResponse response = client.DeleteObjects(request);
}
catch (DeleteObjectsException doe)
{
// Catch error and list error details
DeleteObjectsResponse errorResponse = doe.Response;
foreach (DeletedObject deletedObject in errorResponse.DeletedObjects)
{
Console.WriteLine("Deleted item " + deletedObject.Key);
}
foreach (DeleteError deleteError in errorResponse.DeleteErrors)
{
Console.WriteLine("Error deleting item " + deleteError.Key);
Console.WriteLine(" Code - " + deleteError.Code);
Console.WriteLine(" Message - " + deleteError.Message);
}