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 }Required

The file to delete: bucket/key as one string, such as invoices/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.signalAbortSignal

Cancels the call when it aborts. The promise then rejects with aborted, and the file may or may not be deleted.

options.timeoutMsnumber

The longest each request may take, in milliseconds. The client’s timeoutMs when 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.

CodeWhen
validation_failedThe path is wrong. issues names each field, such as path.key
not_foundThe bucket or the file does not exist. resource says which
forbiddenThe API key may not delete files

Every call can also fail with the codes listed on SpaceError, such as timeout and network_error.

Example

delete-draft.ts
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