Removes the specified objects from Amazon S3.
![](../icons/collapse_all.gif)
C# |
public DeleteObjectsResponse DeleteObjects( DeleteObjectsRequest request )
![](../icons/collapse_all.gif)
- request (DeleteObjectsRequest)
- The DeleteObjectsRequest that defines the parameters of the operation.
![](../icons/collapse_all.gif)
Returns a DeleteObjectsResponse from S3.
![](../icons/collapse_all.gif)
The DeleteObjects operation removes the specified object from Amazon S3. Once deleted, there is no method to restore or undelete the objects.
DeleteObjectsException will be thrown if any of the deletes fail.
![](../icons/collapse_all.gif)
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.
![](../icons/CopyCode.gif)
// Create a client AmazonS3Client client = new AmazonS3Client(); // Create a DeleteObject request DeleteObjectsRequest request = new DeleteObjectsRequest { BucketName = "SampleBucket", Keys = new List<KeyVersion> { new KeyVersion("Item1"), // Versioned item new KeyVersion("Item2", "Rej8CiBxcZKVK81cLr39j27Y5FVXghDK"), // Item in subdirectory new KeyVersion("Logs/error.txt") } }; try { // Issue request DeleteObjectsResponse response = client.DeleteObjects(request); } catch (DeleteObjectsException doe) { // Catch error and list error details DeleteObjectsErrorResponse errorResponse = doe.ErrorResponse; 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); } }
![](../icons/collapse_all.gif)
Exception | Condition |
---|---|
ArgumentNullException | |
WebException | |
AmazonS3Exception | |
DeleteObjectsException |
If any objects are not deleted during the operation.
|
![](../icons/collapse_all.gif)
DeleteObjects()()()()