All Products
Search
Document Center

Object Storage Service:DeleteMultipleObjects

Last Updated:Feb 05, 2024

Deletes multiple objects from a bucket.

Note
  • A call to the DeleteMultipleObjects operation can delete up to 1,000 objects.

  • Deleted objects cannot be recovered. Proceed with caution. For more information about how to delete objects, see Delete objects.

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, the specified object versions 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

Object Storage Service (OSS) verifies the body of a DeleteMultipleObjects request based on the following headers and deleted the specified objects only when the verification is successful.

Header

Type

Required

Example

Description

Encoding-type

String

No

url

The encoding type of the object names in the response. The value of the Key element is UTF-8 encoded. If the Key element 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 element in the response.

By default, this header is left empty.

Valid value: url

Content-Length

String

Yes

151

The 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-MD5

String

Yes

ohhnqLBJFiKkPSBO1eNaUA==

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 header is specified in the request, 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.

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

Example

Description

Delete

Container

Yes

N/A

The container that stores the DeleteMultipleObjects request content.

Child nodes: Object and Quiet

Parent nodes: none

Object

Container

Yes

N/A

The container that stores the information about an object.

Child nodes: Key

Parent nodes: Delete

Key

String

Yes

test.jpg

The name of the object that you want to delete.

Parent nodes: Object

Quiet

Enumerated string

Yes

false

Specifies 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 message body of the response contains information about all the deleted objects. By default, this mode is used.

Valid values: true and false

Default value: false.

Parent nodes: Delete

VersionId

String

No

CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****

The version ID of the object that you want to delete.

Parent nodes: Object

Response elements

Element

Type

Example

Description

Deleted

Container

N/A

The 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

DeleteResult

Container

N/A

The container that stores the result of the DeleteMultipleObjects request.

Child nodes: Deleted

Parent nodes: none

Key

String

demo.jpg

The name of the deleted object.

Parent nodes: Deleted

EncodingType

String

url

The 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

DeleteMarker

Boolean

true

Indicates 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.

DeleteMarkerVersionId

String

THUQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****

The version ID of the delete marker.

Parent nodes: Deleted

Examples

  • Sample request in which the Quiet mode is 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 response

    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 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 response

    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 in which no version IDs are 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 response

    In the following example, the version IDs of the two objects that you want to delete (multipart.dat and test.jpg) are not specified. Therefore, OSS adds delete markers to the two objects, and returns <DeleteMarker>true</DeleteMarker> and <DeleteMarkerVersionId>XXXXXX</DeleteMarkerVersionId>.

    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 in which version IDs are specified

    Note

    You must specify both the Key and VersionId elements.

    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 response

    In this example, the key and 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 element

    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 response

    • The Key element indicates the name of the deleted object and the VersionId element 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>

SDK

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

References

  • For more information about the API operation that you can call to delete a single object, see DeleteObject.

  • For formation about how to automatically delete objects, see Overview.

Error codes

Error code

HTTP status code

Description

InvalidDigest

400

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.

MalformedXML

400

  • The size of the message body exceeds 2 MB.

  • The number of objects that you specified in the DeleteMultipleObjects request exceeds 1,000.

FileImmutable

409

The data that you want to delete or modify is protected by a retention policy.