• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Versioning Management
  5. Deleting Versioning Objects

Deleting Versioning Objects

Deleting a Single Versioning Object

You can call ObsClient.deleteObject to pass the version ID (versionId) to delete a versioning object. Sample code is as follows:

# Import the module.
from com.obs.client.obs_client import ObsClient
 
# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    
    server='yourdomainname'
)

resp = obsClient.deleteObject('bucketname', 'objectkey', versionId='versionid')
if resp.status < 300:    
    print('requestId:', resp.requestId)
else:    
    print('errorCode:', resp.errorCode)    
    print('errorMessage:', resp.errorMessage)

Batch Deleting Versioning Objects

You can call ObsClient.deleteObjects to pass the version ID (versionId) of each to-be-deleted object to batch delete them. Sample code is as follows:

# Import the module.
from com.obs.client.obs_client import ObsClient
 
# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    
    server='yourdomainname'
)

from com.obs.models.delete_objects_request import DeleteObjectsRequest, Object

object1 = Object(key='objectkey1', versionId='version1')
object2 = Object(key='objectkey2', versionId='version2')

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)