Updated on 2022-02-10 GMT+08:00

DELETE Objects

API Description

You can use this API to batch delete objects from a specified bucket.

Method Definition

1. ObsClient->deleteObjects(array $parameter)
2. ObsClient->deleteObjectsAsync(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

Objects

indexed array

Mandatory

List of objects to be deleted

  

Key

string

Mandatory

Object name

VersionId

string

Optional

Version ID of the object to be deleted

Quiet

boolean

Optional

Response mode of a batch deletion request. If this field is set to false, objects involved in the deletion will be returned. If this field is set to true, only objects failed to be deleted will be returned.

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

Deleteds

indexed array

List of successfully deleted objects

  

Key

string

Object name

VersionId

string

Object version ID

DeleteMarker

boolean

Whether the deleted object is a delete marker

DeleteMarkerVersionId

string

Version ID of the delete marker

Errors

indexed array

List of objects failed to be deleted

  

Key

string

Object name

VersionId

string

Object version ID

Code

string

Error code of the deletion failure

Message

string

Error message of the deletion failure

Sample Code

try {
       $resp = $obsClient->deleteObjects ( [ 
              'Bucket' => 'bucketname',
              'Quiet' => false,
              'Objects' => [ 
                     [ 
                           'Key' => 'objectkey1',
                           'VersionId' => null 
                     ],
                     [ 
                           'Key' => 'objectkey2',
                           'VersionId' => null 
                     ] 
              ] 
       ] );
       printf ( "RequestId:%s\n", $resp ['RequestId'] );
       printf ( "Deleteds:\n" );
       foreach ( $resp ['Deleteds'] as $index => $deleted ) {
              printf ( "Deleteds[%d]", $index + 1 );
              printf ( "Key:%s\n", $deleted ['Key'] );
              printf ( "VersionId:%s\n", $deleted ['VersionId'] );
              printf ( "DeleteMarker:%s\n", $deleted ['DeleteMarker'] );
              printf ( "DeleteMarkerVersionId:%s\n", $deleted ['DeleteMarkerVersionId'] );
       }
       printf ( "Errors:\n" );
       foreach ( $resp ['Errors'] as $index => $error ) {
              printf ( "Errors[%d]", $index + 1 );
              printf ( "Key:%s\n", $error ['Key'] );
              printf ( "VersionId:%s\n", $$error ['VersionId'] );
              printf ( "Code:%s\n", $error ['Code'] );
              printf ( "Message:%s\n", $error ['Message'] );
       }
} catch ( Obs\Common\ObsException $obsException ) {
       printf("StatusCode:%s\n", $obsException->getStatusCode());
}