Delete Objects

The following SDK methods will allow you to perform delete operations in Stratus. The Bucket reference used in the below code snippet is the component instance.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section

Parameters Used

Parameter Name Data Type Definition
key String A Mandatory parameter. Will hold the complete name of the object along with it's path.
versionId String An Optional parameter. If Versioning is enabled for your bucket then, this param will help you refer to a particular version using its unique Version ID.
ttl int An Optional parameter. It allows you to schedule your delete operations. For example, if you provide the value of ttl as 60, the delete operation will only occur after 60 seconds. The value of ttl has to be >= 60 seconds.

Delete a Single Object

Using this SDK method, you can delete a particular object by passing the object name to the deleteObject() method.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section

Ensure the following packages are imported

    
copy
import org.json.simple.JSONObject;
    
copy
int ttl = 200; //time to live in seconds JSONObject deleteRes = bucket.deleteObject("sam/out/sample.txt", "versionId", ttl); System.out.println(deleteRes);
Note: If Versioning is enabled on the bucket and no specific versionId is provided, deleting an object will remove all versions of that object by default.

Delete Multiple Objects

Using this SDK method, you can delete multiple objects by passing the names of the objects that need to be deleted as an array.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section

Ensure you provide the versionId of the object if you enabled Versioning for your bucket. You can also schedule your delete operation using the ttl variable. For example, if you provide the value of ttl as 60, the delete operation will only occur after 60 seconds.

Ensure the following packages are imported

    
copy
import com.zc.component.stratus.beans.ZCDeleteObjectRequest; import org.json.simple.JSONObject;
    
copy
ZCDeleteObjectRequest deleteRequest = ZCDeleteObjectRequest.getInstance(); deleteRequest.setObject("sam/out/sample.txt", "76dhe7yr738rud"); deleteRequest.setObject("sam/out/add.txt", "cjdhf73673g7yt7d"); deleteRequest.setTTL(70); JSONObject res = bucket.deleteObjects(deleteRequest); System.out.println(res);

Truncate Bucket

Using this SDK method you will be able to essentially every single object present in the bucket.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section

Ensure the following packages are imported

    
copy
import org.json.simple.JSONObject;
    
copy
JSONObject truncateRes = bucket.truncate(); System.out.println(truncateRes);

Delete a Path in the Bucket

Using this SDK, you will be able to delete all the objects present in a path. You need to pass the complete path to the deletePath() method.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section

Ensure the following packages are imported

    
copy
import org.json.simple.JSONObject;
    
copy
JSONObject res = bucket.deletePath("sam/"); System.out.println(res);
Note: Ensure that you provide the exact path. If an incorrect path is provided, the delete action will get scheduled, but it will result in an error.

Last Updated 2025-06-03 12:50:19 +0530 +0530