• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js SDK)
  4. Objects-Related APIs
  5. DELETE Objects

DELETE Objects

API Description

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

Method Definition

ObsClient.deleteObjects(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Objects

Array

Mandatory

List of objects to be deleted

  

Key

String

Mandatory

Object name

VersionId

String

Optional

Object version ID

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 (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Deleteds

Array

List of successfully deleted objects

  

Key

String

Name of the deleted object

VersionId

String

Version ID of the deleted object

DeleteMarker

String

Whether the deleted object is a delete marker

DeleteMarkerVersionId

String

Version ID of the delete marker

Errors

Array

List of the objects that fail to be deleted

  

Key

String

Name of the object that fails to be deleted

VersionId

String

Version ID of the object that fails to be deleted

Code

String

Error code of the deletion failure

Message

String

Error message of the deletion failure

Sample Code

obsClient.deleteObjects({
       Bucket:'bucketname',
       Quiet:false,
       Objects:[{Key:'objectkey'},{Key:'objectkey2'}]
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('Deleteds:');
                     for(let i=0;i<result.InterfaceResult.Deleteds.length;i++){
                           console.log('Deleted[' + i + ']:');
                           console.log('Key-->'+result.InterfaceResult.Deleteds[i]['Key']);
                           console.log('VersionId-->' + result.InterfaceResult.Deleteds[i]['VersionId']);
                           console.log('DeleteMarker-->' + result.InterfaceResult.Deleteds[i]['DeleteMarker']);
                           console.log('DeleteMarkerVersionId-->' + result.InterfaceResult.Deleteds[i]['DeleteMarkerVersionId']);
                     }
                     console.log('Errors:');
                     for(let i=0;i<result.InterfaceResult.Errors.length;i++){
                           console.log('Error[' + i + ']:');
                           console.log('Key-->' + result.InterfaceResult.Errors[i]['Key']);
                           console.log('VersionId-->' + result.InterfaceResult.Errors[i]['VersionId']);
                           console.log('Code-->' + result.InterfaceResult.Errors[i]['Code']);
                           console.log('Message-->' + result.InterfaceResult.Errors[i]['Message']);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});