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.
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.
Ensure the following packages are imported
copyimport org.json.simple.JSONObject;
copyint ttl = 200; //time to live in seconds JSONObject deleteRes = bucket.deleteObject("sam/out/sample.txt", "versionId", ttl); System.out.println(deleteRes);
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.
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
copyimport com.zc.component.stratus.beans.ZCDeleteObjectRequest; import org.json.simple.JSONObject;
copyZCDeleteObjectRequest 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.
Ensure the following packages are imported
copyimport org.json.simple.JSONObject;
copyJSONObject 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.
Ensure the following packages are imported
copyimport org.json.simple.JSONObject;
copyJSONObject res = bucket.deletePath("sam/"); System.out.println(res);
Last Updated 2025-06-03 12:50:19 +0530 +0530
Yes
No
Send your feedback to us