You can call this operation to delete multiple objects from the same bucket.

Note You can delete a maximum of 1,000 objects at a time by calling DeleteMultipleObjects.

Versioning

You can use DeleteMultipleObjects to delete multiple objects from a versioning-enabled bucket. If you do not specify the version IDs in your request, delete markers are added. If you specify the version IDs 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

OSS verifies the received message body based on the following headers, and deletes the object only when the attributes of the message body conform to the headers.

Header Type Required Description
Encoding-type String No 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 Key parameter value in the response.

Default value: none

Valid value: url

Content-Length String Yes The length of the HTTP message body.

OSS verifies the received message body based on this header, and deletes the object only when the length of the message body is the same as this header.

Content-MD5 String Yes The Content-MD5 header value is a string calculated by using the MD5 algorithm. This header is used to check whether the content of the received message is same with that of the sent message. After the Content-MD5 request header is uploaded, OSS calculates the MD5 hash of the received object and checks whether the calculated MD5 hash is the same as the MD5 hash provided in the request.
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

Element Type Required Description
Delete Container Yes The container that stores the DeleteMultipleObjects request.

Child nodes: one or more Object elements and the Quite element

Parent node: none

Object Container Yes The container that stores the information about the object.

Child nodes: Key

Parent node: Delete

Key String Yes The name of the object to be deleted.

Parent node: Object

Quiet Boolean Yes Enables the Quiet response mode.

DeleteMultipleObjects provides the following two response modes:

  • Quiet: The message body of the response returned by OSS includes only objects that fail to be deleted. If all objects are deleted successfully, the response does not include a message body.
  • Verbose: The message body of the response returned by OSS includes the results of all deleted objects. By default, this mode is used.

Valid values: true (enables the Quiet mode) and false (enables the Verbose mode)

Default value: false

Parent node: Delete

VersionId String No The version of the object that you want to delete.

Parent node: Object

Response elements

Element Type Description
Deleted Container The container that stores the successfully deleted objects.

Child nodes: Key

Parent node: DeleteResult

DeleteResult Container The container that stores the returned results of the DeleteMultipleObjects request.

Child nodes: Deleted

Parent node: none

Key String The name of the object to be deleted.

Parent node: Deleted

EncodingType String The encoding type for the returned results. If encoding-type is specified in the request, the object name is encoded in the returned result.

Parent node: Container

DeleteMarker Boolean Indicates whether the specified version is a delete marker. true: The specified version is a delete marker. false: The specified version is not a delete marker.
Note This element is returned only when a delete marker is created or permanently deleted, and the value is true.
DeleteMarkerVersionId String The version ID of the delete marker.

Parent node: Deleted

Examples

  • Sample request with the Quiet mode disabled:
    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 request with the Quiet mode 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 request when the versionId parameter is not specified in the DeleteMultipartObject request:
    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 the preceding example, the version IDs of the two objects to be deleted (multipart.dat and test.jpg) are not specified. Therefore, OSS adds delete markers for 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 request when the versionId parameter is specified to delete the specified version of the object:
    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 the preceding example, the key and the version ID of the object to be deleted 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 when the versionId parameter is specified to delete a delete marker:
    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 the preceding example, the returned Key indicates the name of the deleted object and the returned VersionId parameter indicates the deleted version of the object.
    • DeleteMarker indicates that the deleted version is a delete marker. DeleteMarkerVersionId indicates the ID of the deleted version. 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>111111</DeleteMarkerVersionId>
        </Deleted>
    </DeleteResult>

SDK

The SDKs of the DeleteMultipleObjects operation for various programming languages:

Error codes

Error code HTTP status code Description
InvalidDigest 400 The error message returned because the Content-MD5 header value of the message body is inconsistent with the Content-MD5 header value in the request header.
MalformedXML 400
  • A DeleteMultipleObjects request can contain a message body of up to 2 MB. The error message returned because the size of the message body exceeds 2 MB.
  • You can delete a maximum of 1,000 objects at a time by calling DeleteMultipleObjects. The error message returned because the number of objects to be deleted at a time exceeds 1,000.
FileImmutable 409 The error message returned because you delete or modify the data. During the protection period, data in the bucket is protected.