This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000 keys.
Namespace: Amazon.S3
Assembly: AWSSDK.dll
Version: 2.0.0.3
Syntax
public virtual DeleteObjectsResponse DeleteObjects( DeleteObjectsRequest request )
Parameters
- request
-
Type: Amazon.S3.Model.DeleteObjectsRequest
Return Value
Type: Amazon.S3.Model.DeleteObjectsResponse
The response from the DeleteObjects service method, as returned by AmazonS3.
Type: Amazon.S3.Model.DeleteObjectsResponse
The response from the DeleteObjects service method, as returned by AmazonS3.
Examples
This example shows how to delete multiple objects in a single request.
Note that the call may not delete all objects. In that case, an exception
will be thrown. This exception will contain the list of encountered
delete errors.
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); } }
Version Information
.NET Framework:
Supported in: 4.5, 4.0, 3.5