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

DELETE Objects

API Description

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

Method Definition

ObsClient.deleteObjects

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

RequestDate

String

or

Date

Optional

Request time

NOTE:

When the parameter type is String, the value must comply with the ISO8601 or RFC822 standards.

Objects

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

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Deleteds

Array

List of successfully deleted objects

  

Key

String

Object name

VersionId

String

Object version ID

DeleteMarker

String

Whether the deleted object is a delete marker

DeleteMarkerVersionId

String

Version ID of the delete marker

Errors

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

obsClient.deleteObjects({
       Bucket:'bucketname',
       Quiet:false,
       Objects:[{Key:'objectkey'},{Key:'objectkey2'}]
},function (err, result) {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('Deleteds:');
                     for(var 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(var 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);
              }
       }
});