Delete Objects

Note: Ensure you have installed the required package to use this SDK method.

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.

copy
await bucket.deleteObject("sam/out/sample.txt");
Note: If Versioning is enabled on the bucket and if a specific versionId is not provided, deleting the object will remove all versions of that object by default.

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.

copy
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.

Notes:
  • 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.
copy
const objectDel = await bucket.deleteObjects(
[
 {
   key: "sam/out/sample.txt",
   versionId: "01hhch20nfkx9hw9ebqy2jnz9d"
 }
], 100);
console.log(objectDel);

Example of Expected Response

copy
{"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.

copy
// To delete an entire path
const res = await bucket.deletePath("sam/out/");
 console.log(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.

Example of Expected Response

copy
{
    "path": "sam/out/",
    "message": "Path deletion scheduled"
}

Truncate Bucket

Using the truncate() SDK method, you can delete every single object stored in the bucket.

copy
const truncateRes = await bucket.truncate();
console.log(truncateRes);

Last Updated 2026-07-02 14:51:41 +0530 IST