Updated on 2026-01-16 GMT+08:00

Batch Deleting Objects

Functions

This operation can be used to batch delete objects in a bucket. The deletion cannot be undone.

Objects can be deleted in batches in either of the following two modes:

  • Quiet mode (Quiet set to True): The returned response includes only results of objects that failed to be deleted.
  • Non-quiet mode (default mode, or Quiet set to False): The returned response includes the deletion result of each requested object in an XML file.

For batch deletion, the request header must contain Content-MD5 and Content-Length, so that the message body can be identified if network transmission error is detected at the server side.

Request Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
POST /?delete HTTP/1.1  
Host: bucketname.obs.region.example.com
Date: date
Authorization: authorization
Content-MD5: MD5
Content-Length: length

<?xml version="1.0" encoding="UTF-8"?>   
<Delete> 
    <Quiet>true</Quiet>  
    <Object> 
        <Key>Key</Key> 
        <VersionId>VersionId</VersionId> 
    </Object>  
    <Object>  
        <Key>Key</Key> 
    </Object> 
</Delete>

Request Parameters

This request involves no parameters.

Request Headers

This request uses common headers. For details, see Table 3.

Request Elements

This request uses elements to specify the list of objects to be deleted in a batch. Table 1 describes the elements.

Table 1 Request elements

Parameter

Mandatory (Yes/No)

Type

Description

Delete

Yes

XML

Definition:

List of objects to be deleted. Delete is the parent node of Object and Quiet.

Constraints:

None

Range:

For details, see Table 2.

Default value:

None

Table 2 Delete parameters

Parameter

Mandatory (Yes/No)

Type

Description

Quiet

No

Boolean

Definition:

Whether to use the quiet mode. If this parameter is set to True, only the results of objects that fail to be deleted are returned.

Constraints:

If this parameter is not set, the default value False is used. If the value is False, the system ignores the value.

Range:

  • True: Only the results of objects that fail to be deleted are returned.
  • False: All object results are returned.

Default value:

False

Object

Yes

XML

Definition:

Object to be deleted. Object is the parent node of Key and VersionId.

Constraints:

None

Range:

For details, see Table 3.

Default value:

None

Table 3 Object parameters

Parameter

Mandatory (Yes/No)

Type

Description

Key

Yes

String

Definition:

Name of the object to be deleted.

Range:

1 to 1,024 characters

Default value:

None

VersionId

No

String

Definition:

Version ID of the object to be deleted. For details about how to obtain an object version, see Listing Objects in a Bucket.

Constraints:

None

Range:

The value must contain 32 characters.

Default value:

None

A maximum of 1,000 objects can be deleted at a time. If you send a request for deleting more than 1,000 objects, OBS returns an error message.

Response Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
HTTP/1.1 status_code
Date: date
Content-Type: application/xml 
Content-Length: length

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<DeleteResult xmlns="http://obs.region.example.com/doc/2015-06-30/">
<Deleted> 
    <Key>Key</Key> 
</Deleted> 
<Error> 
    <Key>Key</Key> 
    <Code>ErrorCode</Code> 
    <Message>Message</Message> 
</Error> 
</DeleteResult>

Response Headers

The response to the request uses common headers. For details, see Table 1.

Response Elements

This response uses elements to return results of deleted objects in a batch. Table 4 describes the elements.

Table 4 Response elements

Parameter

Type

Description

DeleteResult

Container

Definition:

Root node of the response message. DeleteResult is the parent node of Deleted, Error, and EncodingType.

Range:

For details, see Table 5.

Table 5 DeleteResult parameters

Parameter

Type

Description

Deleted

Container

Definition:

Container for successful deletion results. Deleted is the parent node of Key, VersionId, DeleteMarker, and DeleteMarkerVersionId.

Range:

For details, see Table 6.

Error

Container

Definition:

Container for the deletion failure result. Error is the parent node of Key, VersionId, Code, and Message.

Range:

For details, see Table 7.

Table 6 Deleted parameters

Parameter

Type

Description

Key

String

Definition:

Object name in each deletion result

Range:

1 to 1,024 characters

VersionId

String

Definition:

Version ID of the deleted object

Range:

The value must contain 32 characters.

DeleteMarker

Boolean

Definition:

If this element is specified, true will be returned when you create or delete a delete marker in a bucket with versioning enabled.

When versioning is enabled for a bucket, a delete request that does not specify a version ID cannot permanently delete the object. Instead, OBS creates a delete marker with a unique version ID. When versioning is suspended for a bucket, a delete request that does not specify a version ID deletes the object whose version ID is null and creates a delete marker with a version ID of null.

Range:

true

DeleteMarkerVersionId

String

Definition:

Version ID of a delete marker to create or delete.

If you create or delete a delete marker in a bucket with versioning enabled, OBS returns this element in the response. This element will be returned in either of the following cases:

  • You send a request that has only the object name but not the version ID specified. In this case, OBS creates a delete marker and returns its version ID in the response.
  • You send a request that has both the object key and version ID (that identifies a delete marker) specified. In this case, OBS deletes the delete marker and returns its version ID in the response.

Range:

The value must contain 32 characters.

Table 7 Error parameters

Parameter

Type

Description

Key

String

Definition:

Object name in each deletion result

Range:

1 to 1,024 characters

Code

String

Definition:

Error code of a deletion failure

Range:

None

Message

String

Definition:

Error message of a deletion failure

Range:

None

VersionId

String

Definition:

Version ID of the deleted object

Range:

The value must contain 32 characters.

Error Responses

1. If the resolution result of an XML request contains more than 1,000 objects, OBS returns 400 Bad Request.

2. If the object key in an XML request is invalid (for example, containing more than 1,024 characters after being encoded with UTF-8), OBS returns 400 Bad Request.

3. If the request header does not contain Content-MD5, OBS returns 400 Bad Request.

Other errors are included in Table 2.

Sample Request

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
POST /test333?delete HTTP/1.1
User-Agent: curl/7.29.0
Host: 127.0.0.1
Accept: */*
Date: WED, 01 Jul 2015 04:34:21 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:8sjZWJlWmYmYnK5JqXaFFQ+vHEg=
Content-MD5: ZPzz8L+hdRJ6qCqYbU/pCw==
Content-Length: 188

<?xml version="1.0" encoding="utf-8"?>
<Delete> 
  <Quiet>true</Quiet>  
  <Object> 
    <Key>obja02</Key> 
  </Object>  
  <Object> 
    <Key>obja02</Key> 
  </Object> 
</Delete>

Sample Response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
HTTP/1.1 200 OK
Server: OBS
x-obs-request-id: 8DF400000163D3FE4CE80340D30B0542
x-obs-id-2: 32AAAQAAEAABAAAQAAEAABAAAQAAEAABCRhY0FBWRm6qjOE1ACBZwS+0KYlPBq0f
Content-Type: application/xml
Date: WED, 01 Jul 2015 04:34:21 GMT
Content-Length: 120

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DeleteResult xmlns="http://obs.example.com/doc/2015-06-30/"/>