Skip to content
Files SDK
Esc
navigateopen⌘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. Two list caveats carry over to the walk:

  • Netlify Blobs exposes no pagination cursor. Call listAll() with no limit and it returns everything in a single page (correct); pass a limit and there is no next page to follow, so the walk stops at that many. On Netlify, omit limit when you mean “walk everything.”
  • Non-recursive adapters (Box, OneDrive, SharePoint) list only the immediate children of the root folder. listAll walks every page, but it can’t descend into subfolders the underlying list never returns.

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, Google Cloud Storage, Firebase Storage, Azure Blob), the local `fs`, in-memory, FTP, SFTP, 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, Bun's S3) 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

Overall timeout in milliseconds, applied to each attempt. 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?