space.fs.exists()
Find out whether a file is stored at a path.
Finds out whether a file is stored at a path. It resolves to false only when storage answers that something in the path does not exist, such as the file or its bucket. Any other failure still rejects, so a wrong API key never reads as a missing file.
space.fs.exists(
path: string | { bucket: string; key: string },
options?: {
signal?: AbortSignal
timeoutMs?: number
}
): Promise<boolean>Parameters
pathstring | { bucket, key }The file:
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.options.timeoutMsnumberThe longest each request may take, in milliseconds. The client’s
timeoutMswhen you leave it out, 30,000 by default.
Returns
A promise for true when a file is stored at the path, and false when storage answers not_found.
A folder is not a file: exists on a folder’s path resolves to false. Use space.fs.list() to look inside a folder.
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 |
forbidden | The API key may not view files |
Every call can also fail with the codes listed on SpaceError, such as timeout and network_error.
Example
import { space } from "digitospace"
const path = "receipts/2026/0001.txt"
if (await space.fs.exists(path)) {
console.log(`${path} is already stored`)
} else {
await space.fs.write(path, "Receipt 0001, Kariakoo branch, TZS 185,000")
}Last updated