Baidu AI Cloud
中国站

百度智能云

Object Storage

Delete Data

Basic Introduction

Deleting data means deleting the file (object) in the storage space (bucket). BOS allows you to perform the following deletion operations: Single Delete: Delete a specified object. Delete in batch: A maximum of 1000 objects can be deleted in a single request. Delete automatically: If you need to delete a large number of objects, and the deleted objects have certain rules, such as periodically deleting objects some days ago, or to empty the entire bucket, it is recommended to use Lifecycle Management to automatically delete the object. After the lifecycle rules are set, BOS will automatically delete expired objects according to the rules, thus greatly reducing the number of times you send deletion requests and improving deletion efficiency.

Operation Method

BOS supports deletion by using API and SDK at the same time, as follows:

Example

The following is a code example for the Java SDK to delete objects, as follows:

Delete a single object :

public void deleteObject(BosClient client, String bucketName, String objectKey) {
    // DeleteObject
    client.deleteObject(bucketName, objectKey);
}

To delete objects in batch, you can refer to the following two methods to delete multiple objects:

// 1.String in Json format
String jsonObjectKeys = "{\"objects\": ["+"{\"key\": \"token1.h\"},"+"{\"key\": \"token2.h\"}"+"]}";
DeleteMultipleObjectsRequest request = new DeleteMultipleObjectsRequest();
request.setBucketName("yourBucketName");
request.setJsonDeleteObjects(jsonObjectKeys);
client.deleteMultipleObjects(request);
// 2.Users only need to specify the specified parameters 
List<String> objectKeys = new ArrayList<String>();
objectKeys.add("object1");
objectKeys.add("object2");
DeleteMultipleObjectsRequest request = new DeleteMultipleObjectsRequest();
request.setBucketName("yourBucketName");
request.setObjectKeys(objectKeys);
DeleteMultipleObjectsResponse response = client.deleteMultipleObjects(request);

Note:

  • Support in deleting up to 1,000 objects in one request. Message body does not exceed 2M. The returned message body contains only object results failed during the deletion process; if all objects are successfully deleted, there is no message body.
Previous
Acquisition of Object Meta
Next
Data Copy