Skip to content
Files SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

list

Cursor-paginated listing with a prefix filter; each item is a StoredFile with a lazy body accessor. listAll walks every page; a delimiter returns folders.

files.list(options?)

Cursor-paginated listing with prefix filter. Each item is a StoredFile with a lazy body accessor.

const { items, cursor } = await files.list({
  prefix: "avatars/",
  limit: 100,
});

if (cursor) {
  const next = await files.list({ prefix: "avatars/", cursor });
}

Walking every page with listAll

list returns one page plus a cursor; most callers actually want “walk everything under this prefix”, which is a manual cursor loop. files.listAll(options?) is that loop as an async iterable:

for await (const file of files.listAll({ prefix: "avatars/" })) {
  console.log(file.key, file.size);
}

Each item is the same StoredFile list yields. prefix scopes the walk; limit sets the page size each underlying list fetches (not a total cap), and a cursor resumes from a prior position. Every page is a real list call, so it honors the client prefix, retries and timeouts, and fires one onAction list event per page. break out of the loop to stop early — no further pages are fetched.

listAll runs on every adapter, since it’s built on list. One list caveat carries over to the walk: the folder-based Box, OneDrive, and SharePoint adapters list one folder at a time and don’t recurse. list reads the folder that prefix points into (everything up to its last /, or the root folder when there’s no prefix), so listAll walks every page of that folder but never descends into its subfolders. Walk each subfolder with its own prefix, discovering them with delimiter: "/".

Listing folders with delimiter

Pass a delimiter to collapse keys at that boundary into common prefixes (“folders”) — the building block for a file-browser UI. With delimiter: "/", a page returns only the files directly under prefix in items, and the subfolders in prefixes (full keys including the trailing delimiter); keys nested deeper are folded into those prefixes rather than listed.

const { items, prefixes } = await files.list({
  prefix: "photos/",
  delimiter: "/",
});

// Render one level of a browser:
for (const folder of prefixes ?? []) {
  console.log("📁", folder); // "photos/2023/", "photos/2024/"
}
for (const file of items) {
  console.log("📄", file.key); // "photos/cover.jpg"
}

prefixes is omitted when no delimiter is set or none are found. The page cursor walks items and prefixes together (a folder counts as one entry against limit); hold prefix and delimiter constant across a paginated sequence, just like prefix alone.

listAll ignores delimiter — it walks the whole tree, so use list directly for the folder view.

Provider support

Options

Both list and listAll take the same options:

PropType
prefix?string

Filter results to keys that start with this string. Omit to list everything in the bucket.

Typestring
cursor?string

Continuation token from a prior result. Pass the `cursor` field of the previous page back in to fetch the next page; omit on the first call. A cursor is only valid for the exact `prefix` **and** `delimiter` it was produced with — hold both constant across a paginated sequence.

Typestring
limit?number

Maximum number of items to return per page. Capped per-provider (most providers max around 1000). Defaults to 1000.

Typenumber
delimiter?string

Collapse keys at this boundary into "folders" (S3-style common prefixes), the building block for a file-browser UI. With `delimiter: "/"` and `prefix: "photos/"`, the page's `items` are only the direct files (`photos/cover.jpg`) and {@link ListResult.prefixes} holds the subfolders (`photos/2023/`, `photos/2024/`) — the keys nested deeper are folded into those prefixes rather than listed. **Supported** by the object-store adapters with native common-prefix listing (S3 and the whole `s3()` family, R2, Bun's S3, Google Cloud Storage, Firebase Storage, Azure Blob), the local `fs`, in-memory, FTP, SFTP, WebDAV, Google Drive, and Cloudinary adapters (any delimiter string), plus the folder-based providers (Vercel Blob, Netlify Blobs, Supabase, Dropbox, Box, OneDrive, SharePoint) which only accept `"/"`. **Throws** a {@link FilesError} on adapters with no folder concept (UploadThing, Appwrite, PocketBase, Convex, Bunny Storage) rather than silently returning a flat list. Check {@link Adapter.supportsDelimiter} to branch at runtime. Must be a non-empty string.

Typestring
signal?AbortSignal

Abort the operation when this signal is aborted. When both constructor and per-call signals are provided, either one can abort the call.

TypeAbortSignal
timeout?number

Timeout in milliseconds, applied to each attempt (not the call as a whole). A timeout aborts the operation and is not retried. `0` or a negative value disables timeout handling.

Typenumber
retries?RetryOptions

Retry provider failures. A number is treated as `{ max: number }`.

TypeRetryOptions

Result

PropType
itemsStoredFile[]
TypeStoredFile[]
prefixes?string[]

Common prefixes ("folders") when {@link ListOptions.delimiter} is set — full keys including the trailing delimiter, e.g. `["photos/2023/", "photos/2024/"]`. Omitted when no delimiter is set or none are found. When the {@link Files} instance has a client `prefix`, these are scoped/stripped identically to item keys.

Typestring[]
cursor?string
Typestring

Was this page helpful?