DeleteMultipleObjects

更新时间:
复制 MD 格式

Deletes multiple objects from a bucket in a single request.

Usage notes

  • A single DeleteMultipleObjects request can delete up to 1,000 objects.

  • If data replication is configured with Sync Additions, Deletions, And Modifications, DeleteMultipleObjects also deletes the corresponding objects in the destination bucket. Deleted objects cannot be recovered. With versioning enabled, DeleteMultipleObjects creates a delete marker for each object, and this action is replicated to the destination bucket.

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

Versioning

On a versioning-enabled bucket, DeleteMultipleObjects inserts a delete marker when no version ID is specified. If a version ID is specified, that version is permanently deleted.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM policies or Bucket Policy.

API

Action

Description

DeleteMultipleObjects

oss:DeleteObject

Deletes multiple objects from a bucket.

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>

当您在OSS ON云盒中调用该接口时,您需要将Host替换为云盒Endpoint。更多信息,请参见云盒Endpoint

Request headers

OSS uses these headers to verify the message body before performing the delete operation.

Name

Type

Required

Example

Description

Encoding-type

String

No

url2

The encoding method for object keys. If a key contains control characters unsupported by XML 1.0, set this to url2. OSS then URL-encodes the Key field in the response.

Default value: none

Valid value: url2

Content-Length

String

Yes

151

The length of the HTTP message body.

OSS verifies the body against this value before deletion.

Content-MD5

String

Yes

ohhnqLBJFiKkPSBO1eNaUA==

The Base64-encoded MD5 hash of the message body. OSS computes and compares this value to verify integrity.

Note

To compute this value: calculate the MD5 hash of the request body to get a 128-bit byte array, then Base64-encode it.

Request elements

Name

Type

Required

Example

Description

Delete

Container

Yes

N/A

The container for the DeleteMultipleObjects request.

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

Parent node: None

Object

Container

Yes

N/A

The container for information about an object.

Child node: Key

Parent node: Delete

Key

String

Yes

test.jpg

The name of the object to delete.

Parent node: Object

Quiet

Enumeration string

No

false

Controls the response mode.

Available response modes:

  • Simple mode (quiet): OSS does not return a message body.

  • Verbose mode (verbose): OSS returns the deletion result for each object. This is the default mode.

Valid values: true (enables simple mode) and false (enables verbose mode)

Default value: false

Parent node: Delete

VersionId

String

No

CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****

The version number of the object to delete.

Parent node: Object

Response elements

Name

Type

Example

Description

DeleteResult

Container

N/A

The container for the result of the DeleteMultipleObjects request.

Child node: Deleted

Parent node: None

Deleted

Container

N/A

The container for each successfully deleted object.

Important

The Deleted element lists only successfully deleted objects. Compare the request list with the response to identify failures.

Child node: Key

Parent node: DeleteResult

Key

String

demo.jpg

The name of the deleted object.

Parent node: Deleted

VersionId

String

version_20211101141621_d137

The version ID.

Parent node: Deleted

DeleteMarker

Boolean

true

Whether the deleted version is a delete marker. Valid values: true and false.

Note

Returned as true only when a delete marker is created or permanently deleted.

Parent node: Deleted

DeleteMarkerVersionId

String

THUQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****

The version ID of the delete marker.

Parent node: Deleted

EncodingType

String

url2

The encoding type for object names in the response. Returned only when Encoding-type is specified in the request.

Parent node: DeleteResult

Examples

  • Sample request with simple response 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: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    
    <?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 with simple response 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: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    
    <?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 without a version ID

    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: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    
    <?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

    Because no version IDs are specified, OSS inserts delete markers for both 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 with a version ID

    Note

    You must specify both the Key and VersionId.

    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: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    
    <?xml version="1.0" encoding="UTF-8"?>
    <Delete> 
      <Quiet>false</Quiet>  
      <Object> 
        <Key>multipart.data</Key>
        <VersionId>CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****</VersionId>
      </Object>
    </Delete>

    Sample response

    The following example shows that 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 a version ID

    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: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    
    <?xml version="1.0" encoding="UTF-8"?>
    <Delete> 
      <Quiet>false</Quiet>  
      <Object> 
        <Key>multipart.data</Key>
        <VersionId>CAEQNRiBgICEoPiC0BYiIGMxZWJmYmMzYjE0OTQ0ZmZhYjgzNzkzYjc2NjZk****</VersionId>
      </Object>
    </Delete>

    Sample response

    • Key and VersionId identify the deleted object.

    • The DeleteMarker and DeleteMarkerVersionId elements confirm that the deleted item is a delete marker. In this case, VersionId and DeleteMarkerVersionId have the same value.

    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 call DeleteMultipleObjects by using the following SDKs:

ossutil command-line tool

The corresponding ossutil command is delete-multiple-objects.

References

  • To delete a single object, use DeleteObject.

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

Error codes

Error code

HTTP status code

Description

InvalidDigest

400

The Content-MD5 value calculated by OSS does not match the Content-MD5 request header value.

MalformedXML

400

  • The message body exceeds 2 MB.

  • More than 1,000 objects are specified in a single DeleteMultipleObjects request.

FileImmutable

409

The bucket is protected by a retention policy. Protected data cannot be deleted or modified.