• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python 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(bucketName, deleteObjectsRequest)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

deleteObjectsRequest

DeleteObjectsRequest

Mandatory

Request parameter of DELETE Objects

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

DeleteObjectsResponse

Response result of DELETE Objects

Sample Code

try:
    from com.obs.models.delete_objects_request import DeleteObjectsRequest, Object 
     
    object1 = Object(key='objectkey', versionId=None) 
    object2 = Object(key='objectkey2', versionId=None) 
     
    resp = obsClient.deleteObjects('bucketname', DeleteObjectsRequest(quiet=False, objects=[object1, object2])) 
          
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        if resp.body.deleted: 
            index = 1 
            for delete in resp.body.deleted: 
                print('delete[' + str(index) + ']') 
                print('key:', delete.key, ',deleteMarker:', delete.deleteMarker, ',deleteMarkerVersionId:', delete.deleteMarkerVersionId) 
                print('versionId:', delete.versionId) 
                index += 1 
        if resp.body.error: 
            index = 1 
            for err in resp.body.error: 
                print('err[' + str(index) + ']') 
                print('key:', err.key, ',code:', err.code, ',message:', err.message) 
                print('versionId:', err.versionId) 
                index += 1 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())