Delete Objects
Parameters Used
| Parameter Name | Data Type | Definition |
|---|---|---|
| key | String | A mandatory parameter. Will hold the complete name of the object along with its path. |
| versionId | String | An optional parameter. If Versioning is enabled for your bucket then this parameter 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. |
The following SDK methods will allow you to perform various types of delete operations on objects stored in a bucket in Stratus. The bucket reference used in the following code snippet is the component instance.
Delete a Single Object
You can delete the required object by passing its complete name to the deleteObject() SDK method.
await bucket.deleteObject("sam/out/sample.txt");
Delete a Specific Version of an Object after a Specific Time
You need to provide the required versionId to the deleteObject() SDK method. You also have the option to schedule the delete operation using the ttl parameter.
For example, if you pass the value of ttl as 100, the delete operation will only occur after 100 seconds.
Always ensure the value of ttl is greater than or equal to 60 seconds.
const options = {
versionId: "01hthq82gwxtfyz6d9j8eg6k2f", // delete the object with given versionId
ttl: 100 // Time to live in number of seconds
};
await bucket.deleteObject("sam/out/sample.txt", options);
Delete Multiple Objects
The deleteObjects() SDK method can be used to delete multiple objects stored in a bucket in Stratus. You need to pass the names of the required objects as an array to the SDK method.
-
If Versioning is enabled for your bucket, ensure you provide the versionId of the object that you are required to delete.
-
Additionally, you also have the option to schedule the delete operation using the ttl parameter.
- For example, if you provide the value of ttl as 100, the delete operation will only occur after 100 seconds.
- Always ensure that the value of ttl is greater than or equal to 60 seconds.
const objectDel = await bucket.deleteObjects(
[
{
key: "sam/out/sample.txt",
versionId: "01hhch20nfkx9hw9ebqy2jnz9d"
}
], 100);
console.log(objectDel);
Example of Expected Response
{"message": "Object Deletion successful."}
Delete a Path in the Bucket
Using the deletePath() SDK method you will be able to delete the required path and all the objects stored in it.
// To delete an entire path
const res = await bucket.deletePath("sam/out/");
console.log(res);
Example of Expected Response
{
"path": "sam/out/",
"message": "Path deletion scheduled"
}
Truncate Bucket
Using the truncate() SDK method, you can delete every single object stored in the bucket.
const truncateRes = await bucket.truncate();
console.log(truncateRes);
Last Updated 2026-07-02 14:51:41 +0530 IST
Yes
No
Send your feedback to us