Recycle bin
Users can configure the bucket trash function to ensure that deleted data remains in the bucket trash, facilitating the subsequent recovery of deleted data. For details, please refer to Bucket Trash Function
Note: 1. Files moved to the bucket trash will continue to be charged until they are completely deleted by the user. For files in the bucket trash, it is recommended that users configure a lifecycle to delete expired files; 2. When a user performs an overwrite operation, the old data will not enter the bucket trash
Enable bucket trash (PutBucketTrash)
| Parameters | Types | Required or not | Description |
|---|---|---|---|
| bucketName | String | Yes | The requested bucket name |
| trashDir | String | No | Specify the name of the bucket trash directory. If not specified, the default bucket trash directory is named ".trash". |
Note: 1. If the bucket trash function has been enabled before, re-enabling it will overwrite the original bucket trash directory name; 2. The name of the bucket trash directory can only contain letters, numbers, Chinese characters, underscores (_), hyphens (-), and decimal points (.). Inclusion of '/' will result in an error; 3. For buckets with the bucket trash function enabled, deleted objects will be moved to the bucket trash (the full name of an object in the bucket trash is: trashDir + '/' + old object name). Objects in buckets without this function enabled, or in buckets with this function enabled but deleted from the trash will be deleted completely 4. Archive storage class files do not support bucket trash, and it will be deleted directly when the archive storage class files are deleted.
The following code sets the bucket trash with a custom name:
1String trashDir="testDir";
2this.client.putBucketTrash(bucketName, trashDir);
The following code sets the default bucket trash:
1this.client.putBucketTrash(bucketName);
Get bucket trash activation information (GetBucketTrash)
| Parameters | Types | Required or not | Description |
|---|---|---|---|
| bucketName | String | Yes | The requested bucket name |
Code example
1GetBucketTrashResponse response=this.client.getBucketTrash(bucketName);
2System.out.println(response.getTrashDir().toString());
Disable bucket trash (DeleteBucketTrash)
| Parameters | Types | Required or not | Description |
|---|---|---|---|
| bucketName | String | Yes | The requested bucket name |
Code example
1this.client.deleteBucketTrash(bucketName);
