Delete Object
Learn how to remove objects from your DID Space. This operation allows you to permanently delete files or directories identified by their unique key.
For general information on managing objects, refer to the Object commands section.
Delete an Object#
Use the DeleteObjectCommand
to remove a specific object from your DID Space. This action is irreversible.
Parameters
Name | Type | Description |
---|---|---|
|
| The unique identifier (path) of the object to be deleted within your DID Space. |
Returns
Name | Type | Description |
---|---|---|
|
| The HTTP status code of the response (e.g., |
|
| The HTTP status message of the response. |
|
| This command does not return any data in the response body. |
Example
import { SpaceClient } from '@did-spaces/client';
import { DeleteObjectCommand } from '@did-spaces/client/commands/object';
async function deleteMyObject(client: SpaceClient, objectKey: string) {
try {
const command = new DeleteObjectCommand({
key: objectKey,
});
const result = await client.send(command);
if (result.statusCode === 200) {
console.log(`Object '${objectKey}' successfully deleted.`);
} else {
console.error(`Failed to delete object '${objectKey}': ${result.statusMessage} (Status: ${result.statusCode})`);
}
} catch (error) {
console.error(`Error deleting object '${objectKey}':`, error);
}
}
// Example usage (assuming client is already initialized)
// const client = new SpaceClient({ wallet, endpoint });
// deleteMyObject(client, 'path/to/your/file.txt');
This example demonstrates how to use the DeleteObjectCommand
to remove an object identified by its key
. The operation will return a status indicating success or failure without any data payload.
Now that you know how to delete objects, you might want to learn how to list existing objects in your space: List Objects.