Reference

FilewayClient

API reference for the FilewayClient engine and its configuration

Constructor

new FilewayClient<TDriver extends BaseDriver>(config: FilewayConfig<TDriver>)

The type parameter is the driver, inferred from config.driver. To annotate a client, use the driver type: FilewayClient<S3Driver>.

config

OptionTypeDescription
driverBaseDriverThe storage driver. See Drivers.
middlewaresMiddlewareHook<TMeta>[]Optional. Middleware run around uploads; inline hooks get the driver's metadata type. See Middleware.
loggerLoggerOptional. Structured logger; receives info per operation and error on failure. See Observability.
onError(error, context) => void | Promise<void>Optional. Called (and awaited) before an error is re-thrown. Aborts are skipped. See Observability.
pluginsFilewayPlugin[]Optional. Event listeners, middleware and routes. See Plugins and Events.
basePathstringOptional. Where client.handler is mounted. Default "/api/fileway".
linksLinksConfigOptional. App-signed download and upload links. See App-signed links.
waitUntil(promise) => voidOptional. The platform's waitUntil (Vercel, Cloudflare Workers), so plugin background work finishes after the response. See Plugins.
retryRetryConfigOptional. Retries transient failures (network, timeout, rate-limited, provider-error, HTTP 429/5xx). See Observability.

upload(stream, options)

Uploads a WHATWG ReadableStream<Uint8Array>.

ParamTypeDescription
streamReadableStream<Uint8Array>The file bytes. Never buffered whole by Local/S3.
optionsUploadOptionsSee the options table below.

Returns Promise<UploadResult<TMeta>> where TMeta is the driver's metadata type.

An upload retries on transient failures only when options.streamFactory is provided (see Retries). Before retrying (or failing), it checks whether the object was stored despite the error and, if so, returns it without re-sending (see Safe retries). delete, get, getUrl, and getPresignedUrl retry automatically.

UploadOptions:

OptionTypeRequiredDescription
filenamestring✅Original file name.
pathstringFolder/path prefix for the stored object.
mimeTypestringContent type.
metadataRecord<string, string>Provider user metadata (see Metadata).
sizenumberKnown byte length: unlocks zero-buffer streaming (see Uploads).
signalAbortSignalCancels the upload in flight (see Uploads).
onProgress(progress) => voidProgress callback (see Uploads).
idstringStable upload ID; the stored name is built from it and reused on every retry. Generated per call when omitted. Reusing an ID overwrites that object.
streamFactory() => ReadableStream<Uint8Array>Re-produces the stream for retry attempts. Required to retry an upload (see Retries). Sync-only today; an async (Promise-returning) variant is planned; see Retrying uploads.

Options for get, delete, getUrl and getPresignedUrl

Each takes an optional second argument:

  • signal (AbortSignal): cancels the request in flight and any pending retries, and rejects with an AbortError. For get, it also stops reading the returned stream.
  • The driver's own options, if it has any. For example Cloudinary accepts { resourceType, deliveryType }:
await client.delete("avatars/u1", { deliveryType: "authenticated", signal });

get(path, options?)

Streams a stored file back as ReadableStream<Uint8Array> (see Downloads). Throws StorageError("not-found") when the file does not exist.

delete(path, options?)

Deletes a stored file. Returns Promise<void>. Deleting a file that does not exist is not an error; any other failure throws a StorageError.

getUrl(path, options?)

Returns the public URL for a stored file (see Downloads).

client.features

What the client can do with its driver and configuration, for example to hide actions in a UI: { list, stat, copy, move, range, downloadLinks, uploadLinks: { app, direct }, maxUploadBytes? }. Fallbacks count: move is true when the driver can copy, and downloadLinks when links is configured. See ClientFeatures.

client.handler

A web-standard request handler that serves plugin routes under basePath: { fetch, GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS }, all the same function. Mount it with export const { GET, POST } = client.handler in Next.js, or fetch: client.handler.fetch on Workers, Bun and Deno. See Plugins and Events.

actor and tags

Every method accepts actor?: string and tags?: Record<string, string>. They are recorded on the operation's event and never passed to the driver.

getUploadStatus(id, options)

Reports whether the upload with id is stored, in progress, or missing, by asking the storage provider. Pass the same filename and path the upload used.

ParamTypeDescription
idstringThe upload's id.
options.filenamestringThe filename the upload used (its extension is part of the stored name).
options.pathstringThe path the upload used.
options.signalAbortSignalCancels the call and any pending retries.

Returns { state: "complete", object }, { state: "pending" }, { state: "missing" }, or { state: "unsupported" } when the driver cannot report status. See Safe retries and upload status.

list(options?)

Returns one page of the files under options.prefix: { objects, folders, cursor? }. Options: prefix, recursive (default false, one folder level), limit (1 to 1000, default 100), cursor, signal. See Managing Files.

listAll(options?)

An async iterator over every file under options.prefix, following cursors. Same options as list without cursor.

stat(path, options?)

Returns the stored file's details (StoredObject: size, contentType, lastModified, typed meta), or null when it does not exist.

copy(from, to, options?) and move(from, to, options?)

Copy or move a file on the same storage. Return nothing. An existing to fails with StorageError("conflict") unless options.overwrite is true. Drivers without a native move copy, then delete. Drivers without the operation throw StorageError("config").

getPresignedUrl(path, options?)

Returns a time-limited, signed download URL (see Downloads). Drivers that cannot presign (such as LocalDriver) use app-signed links when links is configured, and throw StorageError("config") otherwise.

ParamTypeDescription
pathstringPath of the stored file.
options.expiresInnumberLifetime in seconds (default 3600). S3, GCS and Azure allow at most 604800 (7 days); Cloudinary and Supabase accept any positive integer.
options.signalAbortSignalCancels the call.
options.disposition"inline" | "attachment"App-signed links: open in the browser or download. Default: inline for images, PDF, audio and video.
options.filenamestringApp-signed links: the download name.
options.idstringApp-signed links: an id passed to links.check.

getPresignedUploadUrl(options)

Returns { url, method: "PUT", headers, id, path }: a signed link a browser can upload one file to, with fetch(url, { method, headers, body }). Options: filename, path, id (default a new UUID), mimeType, maxSize (default the driver's limit; required when it has none), expiresIn (default 900), direct and size.

By default the file goes through your app (client.handler, needs links). With direct: true, or when links is not configured, S3, Google Cloud and Azure return a link straight to the bucket; size (the exact byte count) is required on S3. Direct uploads skip middleware, plugins and the upload event. See Upload links and Direct upload links.

Was this page helpful?

On this page