Deletes multiple objects from a bucket.
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.
Header | Type | Required | Description |
---|---|---|---|
Encoding-type | String | No | The encoding type of the object name 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.
Default value: null Valid value: url |
Content-Length | String | Yes | The length of the HTTP message body.
OSS verifies 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 the header. |
Content-MD5 | String | Yes | The Content-MD5 header value is a string calculated by using the MD5 algorithm. The
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
Element | Type | Required | Description |
---|---|---|---|
Delete | Container | Yes | The container that stores the DeleteMultipleObjects request.
Child nodes: Object and Quite Parent nodes: none |
Object | Container | Yes | The container that stores the information about the object.
Child nodes: Key Parent nodes: Delete |
Key | String | Yes | The name of the object that you want to delete.
Parent nodes: Object |
Quiet | Enumerated string | Yes | Specifies whether to enable the Quiet response mode.
The DeleteMultipleObjects operation provides the following two response modes:
Valid values: true (enables the Quiet mode) and false (enables the Verbose mode) Default value: false Parent nodes: Delete |
VersionId | String | No | The version ID of the object that you want to delete.
Parent nodes: Object |
Response elements
Element | Type | Description |
---|---|---|
Deleted | Container | The container that stores the deleted objects.
Child nodes: Key Parent nodes: DeleteResult |
DeleteResult | Container | The container that stores the returned results of the DeleteMultipleObjects request.
Child nodes: Deleted Parent nodes: none |
Key | String | The name of the deleted object.
Parent nodes: 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 nodes: 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 if a delete marker is created or permanently deleted,
and the value is true.
|
DeleteMarkerVersionId | String | 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 responsesHTTP/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 responsesHTTP/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 requests when version IDs are specified to delete delete markers
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 returned Key parameter 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>
SDKs
You can use OSS SDKs for the following programming languages to call the DeleteMultipleObjects operation:
Error codes
Error code | HTTP status code | Description |
---|---|---|
InvalidDigest | 400 | The 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. |
MalformedXML | 400 |
|
FileImmutable | 409 | The error message returned because the data that you want to delete or modify is protected by a retention policy. |