space.fs.delete()
Delete a file from a bucket.
Deletes a file. This cannot be undone. To delete an empty folder, use space.fs.rmdir(), and to delete a whole bucket, space.fs.buckets.delete().
space.fs.delete(
path: string | { bucket: string; key: string },
options?: {
signal?: AbortSignal
timeoutMs?: number
}
): Promise<void>Parameters
pathstring | { bucket, key }The file to delete:
bucket/keyas one string, such asinvoices/2026/0001.pdf, or an object such as{ bucket: "invoices", key: "2026/0001.pdf" }.- The bucket is 3 to 63 lowercase letters, digits, and single hyphens, starting and ending with a letter or digit.
- The key is 1 to 1,024 bytes. It cannot start or end with
/, hold//, have a folder named.or.., or hold control characters.
options.signalAbortSignalCancels the call when it aborts. The promise then rejects with
aborted, and the file may or may not be deleted.options.timeoutMsnumberThe longest each request may take, in milliseconds. The client’s
timeoutMswhen you leave it out, 30,000 by default.
Returns
A promise that resolves with no value once the file is deleted.
Errors
The promise rejects with a SpaceError. The call never throws before it returns the promise, and when an argument is wrong, nothing is sent.
| Code | When |
|---|---|
validation_failed | The path is wrong. issues names each field, such as path.key |
not_found | The bucket or the file does not exist. resource says which |
forbidden | The API key may not delete files |
Every call can also fail with the codes listed on SpaceError, such as timeout and network_error.
Example
import { SpaceError, space } from "digitospace"
try {
await space.fs.delete("invoices/drafts/0001.pdf")
} catch (error) {
if (error instanceof SpaceError && error.code === "not_found") {
console.log("Already gone")
} else {
throw error
}
}Last updated