Deletes multiple objects from a bucket.

Note You can delete up to 1,000 objects at a time by calling the DeleteMultipleObjects operation.

Versioning

You can call the DeleteMultipleObjects operation to delete multiple objects from a versioned bucket. If you do not specify the version IDs of the objects that you want to delete in your request, delete markers are added to the objects. If you specify the version IDs of the objects that you want to delete in your request, objects with the specified version IDs are permanently deleted.

Request syntax

POST /?delete HTTP/1.1
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Date: GMT Date
Content-Length: ContentLength
Content-MD5: MD5Value
Authorization: SignatureValue
<?xml version="1.0" encoding="UTF-8"?>
<Delete>
  <Quiet>true</Quiet>
  <Object>
    <Key>key</Key>
  </Object>
...
</Delete>

Request headers

The following table describes the headers contained in DeleteMultipleObjects requests. Object Storage Service (OSS) verifies the message bodies of DeleteMultipleObjects requests based on these headers and delete the objects only when the verification is successful.

HeaderTypeRequiredExampleDescription
Encoding-typeString NourlThe encoding type of the object names in the response. The value of the Key parameter is UTF-8 encoded. If the Key parameter includes control characters that are not supported by the XML 1.0 standard, you can specify this header to encode the value of the Key parameter in the response.

This parameter is empty by default.

Valid value: url

Content-LengthString Yes151The length of the HTTP message body.

OSS uses this header to verify the message body of the request and deletes the specified objects only when the length of the message body is the same as the value of this header.

Content-MD5StringYesohhnqLBJFiKkPSBO1eNaUA==The MD5 hash calculated by using the MD5 algorithm. This header is used to check whether the content of the received message is the same as that of the sent message. After the Content-MD5 request header is uploaded, OSS calculates the MD5 hash based on the message body and checks whether the calculated MD5 hash is the same as the Content-MD5 value specified in the request header.
Note To obtain the value of the Content-MD5 header, encrypt the message body of the DeleteMultipleObjects request by using the MD5 algorithm to obtain a 128-bit byte array, and then encode the byte array in Base64.

Request elements

ElementTypeRequiredExampleDescription
DeleteContainer YesN/AThe container that stores the DeleteMultipleObjects request content.

Child nodes: Object and Quite

Parent nodes: none

ObjectContainer YesN/AThe container that stores the information about an object.

Child nodes: Key

Parent nodes: Delete

KeyStringYestest.jpgThe name of the object that you want to delete.

Parent nodes: Object

QuietEnumerated string YesfalseSpecifies whether to enable the Quiet return mode.

The DeleteMultipleObjects operation provides the following return modes:

  • quiet: The response does not include a message body.
  • verbose: The response includes a message body that contains the information about all deleted objects. By default, this mode is used.

Valid values: true and false

Default value: false

Parent nodes: Delete

VersionIdStringNoCAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****The version ID of the object that you want to delete.

Parent nodes: Object

Response elements

ElementTypeExampleDescription
DeletedContainerN/AThe container that stores information about the deleted objects.
Important The Deleted response element contains information only about the deleted objects and does not contain information about the objects that fail to be deleted. To obtain the names of the objects that fail to be deleted in the DeleteMultipleObjects operation, you can compare values of the Delete header in the request and the values of the Deleted header in the response.

Child nodes: Key

Parent nodes: DeleteResult

DeleteResultContainerN/AThe container that stores the result of the DeleteMultipleObjects request.

Child nodes: Deleted

Parent nodes: none

KeyString demo.jpgThe name of the deleted object.

Parent nodes: Deleted

EncodingTypeString urlThe encoding type of the name of the deleted object in the response. If encoding-type is specified in the request, the object name is encoded in the returned result.

Parent nodes: Container

DeleteMarkerBooleantrueIndicates whether the deleted version is a delete marker. true: The deleted version is a delete marker. false: The specified version is not a delete marker.
Note The DeleteMarker element is included in the response only when the DeleteMultipleObjects operation involves the creation or permanent deletion of a delete marker.
DeleteMarkerVersionIdStringTHUQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****The version ID of the delete marker.

Parent nodes: Deleted

Examples

  • Sample requests in which the Verbose mode is enabled
    POST /?delete HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Wed, 29 Feb 2012 12:26:16 GMT
    Content-Length:151
    Content-MD5: ohhnqLBJFiKkPSBO1eNaUA==
    Authorization: OSS qn6qrrqxo2oawuk53otfjbyc:+z3gBfnFAxBcBDgx27Y/jEfb****
    <?xml version="1.0" encoding="UTF-8"?>
    <Delete> 
      <Quiet>false</Quiet>  
      <Object> 
        <Key>multipart.data</Key> 
      </Object>  
      <Object> 
        <Key>test.jpg</Key> 
      </Object>  
      <Object> 
        <Key>demo.jpg</Key> 
      </Object> 
    </Delete>
    Sample responses
    HTTP/1.1 200 OK
    x-oss-request-id: 78320852-7eee-b697-75e1-b6db0f4849e7
    Date: Wed, 29 Feb 2012 12:26:16 GMT
    Content-Length: 244
    Content-Type: application/xml
    Connection: keep-alive
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <DeleteResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
        <Deleted>
           <Key>multipart.data</Key>
        </Deleted>
        <Deleted>
           <Key>test.jpg</Key>
        </Deleted>
        <Deleted>
           <Key>demo.jpg</Key>
        </Deleted>
    </DeleteResult>
  • Sample requests in which the Quiet mode is enabled
    POST /?delete HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Wed, 29 Feb 2012 12:33:45 GMT
    Content-Length:151
    Content-MD5: ohhnqLBJFiKkPSBO1eNaUA==
    Authorization: OSS qn6qrrqxo2oawuk53otfjbyc:WuV0Jks8RyGSNQrBca64kEEx****
    <?xml version="1.0" encoding="UTF-8"?>
    <Delete> 
      <Quiet>true</Quiet>  
      <Object> 
        <Key>multipart.data</Key> 
      </Object>  
      <Object> 
        <Key>test.jpg</Key> 
      </Object>  
      <Object> 
        <Key>demo.jpg</Key> 
      </Object> 
    </Delete>
    Sample responses
    HTTP/1.1 200 OK
    x-oss-request-id: 559CC9BDC755F95A64485981
    Date: Wed, 29 Feb 2012 12:33:45 GMT
    Content-Length: 0
    Connection: keep-alive
    Server: AliyunOSS
  • Sample requests in which version IDs are not specified
    POST /?delete HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 04:20:03 GMT
    Content-MD5: xSLOYWaPC86RPwWXNiFeXg==
    Authorization: OSS xq39jyxyrddzvvh:/G5kxMIw1ilMQjPp2HkJEp5q****
    <?xml version="1.0" encoding="UTF-8"?>
    <Delete> 
      <Quiet>false</Quiet>  
      <Object> 
        <Key>multipart.data</Key>
      </Object>  
      <Object> 
        <Key>test.jpg</Key> 
      </Object>
    </Delete>

    Sample responses

    In this example, the version IDs of the two objects to be deleted (multipart.data and test.jpg) are not specified. Therefore, OSS adds delete markers to the two objects, and returns <DeleteMarker>true</DeleteMarker> and <DeleteMarkerVersionId>XXXXXX</DseleteMarkerVersionId>.

    HTTP/1.1 200 OK
    x-oss-request-id: 5CAC1D73B7AEADE01700****
    Date: Tue, 09 Apr 2019 04:20:03 GMT
    Content-Type: application/xml
    Connection: keep-alive
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <DeleteResult>
        <Deleted>
           <Key>multipart.data</Key>
           <DeleteMarker>true</DeleteMarker>
           <DeleteMarkerVersionId>CAEQMhiBgIDXiaaB0BYiIGQzYmRkZGUxMTM1ZDRjOTZhNjk4YjRjMTAyZjhl****</DeleteMarkerVersionId>
        </Deleted>
        <Deleted>
           <Key>test.jpg</Key>
           <DeleteMarker>true</DeleteMarker>
           <DeleteMarkerVersionId>CAEQMhiBgIDB3aWB0BYiIGUzYTA3YzliMzVmNzRkZGM5NjllYTVlMjYyYWEy****</DeleteMarkerVersionId>
        </Deleted>
    </DeleteResult>
  • Sample requests in which version IDs are specified
    Note You must specify the name of the object when you specify the VersionId parameter.
    POST /?delete HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 06:09:34 GMT
    Content-Length:151
    Content-MD5: 2Tpk+dL/tGyuSA+YCEuSVg==
    Authorization: OSS qac50zy2vbvbq4z:/pingCxyqfxc0+50Bfi2SX9c****
    <?xml version="1.0" encoding="UTF-8"?>
    <Delete> 
      <Quiet>false</Quiet>  
      <Object> 
        <Key>multipart.data</Key>
        <VersionId>CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****</VersionId>
      </Object>
    </Delete>

    Sample responses

    In this example, the key and the version ID of the deleted object are returned.

    HTTP/1.1 200 OK
    x-oss-request-id: 5CAC371EB7AEADE01700****
    Date: Tue, 09 Apr 2019 06:09:34 GMT
    Content-Length: 244
    Content-Type: application/xml
    Connection: keep-alive
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <DeleteResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
        <Deleted>
           <Key>multipart.data</Key>
           <VersionId>CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****</VersionId>
        </Deleted>
    </DeleteResult>
  • Sample request to delete a delete marker by specifying the versionId parameter
    POST /?delete HTTP/1.1
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 06:14:50 GMT
    Content-Length: 178
    Content-MD5: dX9IFePFgYhmINvAhG30Bg==
    Authorization: OSS 9dfwrokza5gf1p7:iyl6IU6TcfFXcu5p0ds5dUdo****
    <?xml version="1.0" encoding="UTF-8"?>
    <Delete> 
      <Quiet>false</Quiet>  
      <Object> 
        <Key>multipart.data</Key>
        <VersionId>CAEQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****</VersionId>
      </Object>
    </Delete>
    Sample responses
    • In this example, the Key parameter indicates the name of the deleted object and the VersionId parameter indicates the deleted version of the object.
    • DeleteMarker indicates that a delete marker is deleted. DeleteMarkerVersionId indicates the version ID of the delete marker. In this case, the values of VersionId and DeleteMarkerVersionId are the same, and DeleteMarker and DeleteMarkerVersionId are returned together.
    HTTP/1.1 200 OK
    x-oss-request-id: 5CAC385AB7AEADE01700****
    Date: Tue, 09 Apr 2019 06:14:50 GMT
    Content-Length: 364
    Content-Type: application/xml
    Connection: keep-alive
    Server: AliyunOSS
    <?xml version="1.0" encoding="UTF-8"?>
    <DeleteResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
        <Deleted>
           <Key>demo.jpg</Key>
           <VersionId>CAEQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****</VersionId>
           <DeleteMarker>true</DeleteMarker>
           <DeleteMarkerVersionId>THUQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****</DeleteMarkerVersionId>
        </Deleted>
    </DeleteResult>

SDKs

You can use OSS SDKs for the following programming languages to call the DeleteMultipleObjects operation:

Error codes

Error codeHTTP status codeDescription
InvalidDigest400The error message returned because the Content-MD5 value that is calculated by OSS based on the message body is different from the Content-MD5 value that is specified in the request header.
MalformedXML400
  • The error message returned because the size of the message body exceeds 2 MB. A DeleteMultipleObjects request can contain a message body of up to 2 MB.
  • The error message returned because the number of objects that you want to delete at a time exceeds 1,000. You can delete up to 1,000 objects at a time by calling the DeleteMultipleObjects operation.
FileImmutable409The error message returned because the data that you want to delete or modify is protected by a retention policy.