Introducing a new way to review your PRs.

Read the announcement

pingdotgg / uploadthing

File uploads for modern web devs

View on GitHub

19 documents · Updated Oct 2, 2026

docs / server-runtime-adapters

Server runtime adapters

Server runtime adapters connect a framework's native request and response types to UploadThing's shared upload handler. They let one file router support Next.js, legacy Next.js, Express, Fastify, H3, and Remix while keeping upload routing and hook behavior consistent. See Core server SDK, Core upload routing, and Upload client protocol for the related server and client flows.

Shared request boundary

An adapter is a framework entry point that performs two jobs: it gives route hooks access to the native framework context and turns the incoming request into a standard Web Request. The shared handler then returns a Web Response, which the adapter presents through the framework's response API.

Request conversion

The conversion step keeps the request method, URL, headers, and JSON body available to the shared handler. Node-style adapters also account for request bodies that a framework has already parsed or that still arrive as a stream. The URL can use forwarded host and protocol headers, or an explicit URL setting when the server sits behind a proxy.

References: packages/…/to-web-request.ts• L7-12 packages/…/to-web-request.ts• L31-54 packages/…/to-web-request.ts• L60-118 packages/…/to-web-request.ts• L120-145

Shared upload handler

Every framework adapter calls makeAdapterHandler. This shared handler loads the file router and serves router metadata on GET. On POST, it selects an upload request, an UploadThing callback, or an error callback from the request path and headers. It validates the route input and file rules, runs route middleware, and returns the upload data needed by the client. Callback work uses the same handler after the storage upload completes.

The framework name passed by each adapter identifies the server runtime in requests sent from the handler to UploadThing. The native framework arguments also flow into middleware and upload hooks, so hooks can use framework features without changing the common upload protocol.

The diagram shows the boundary between a framework adapter and the shared handler.

flowchart LR
    A[Framework request] --> B[Runtime adapter]
    B --> C[Web Request]
    C --> D[Shared upload handler]
    D --> E[Router metadata or upload response]
    D --> F[Middleware and upload hooks]
    E --> G[Framework response]

References: packages/…/handler.ts• L50-74 packages/…/handler.ts• L75-101 packages/…/handler.ts• L103-239 packages/…/handler.ts• L409-472 packages/…/handler.ts• L474-738

Framework entry points

Each entry point exposes the same route-builder model and accepts a FileRouter plus optional server configuration. The main difference is the shape of the framework request and the way the returned Web response is sent back to the framework.

Next.js App Router

The Next.js adapter targets route handlers in the App Router. It accepts a NextRequest, passes that request to the shared handler as both the hook context and the Web request, and returns one handler for both GET and POST exports. The route file therefore supplies the framework's URL while the adapter supplies the common upload behavior.

References: packages/…/next.ts• L21-39

Next.js Pages Router

The legacy Next.js adapter targets Pages API routes. It keeps both NextApiRequest and NextApiResponse available to hooks, while converting the API request into a Web Request for the shared handler. After handling the request, it copies the status and headers and sends the JSON response through the Pages API response object.

References: packages/…/next-legacy.ts• L22-53 packages/…/to-web-request.ts• L60-118

Express

The Express adapter returns a router that handles all methods at its mounted path. It reads or accepts the JSON request body, converts the request to the Web form, and maps the shared response status and headers to Express. A response body is streamed when present so the framework can finish the HTTP response without changing the shared handler's result.

References: packages/…/express.ts• L27-61

Fastify

The Fastify adapter registers the UploadThing endpoint on /api/uploadthing and completes registration through Fastify's callback. It converts the Fastify request to a Web Request, keeps the Fastify request and reply objects for hooks, and maps the shared response to Fastify's status, headers, and body APIs.

References: packages/…/fastify.ts• L22-54

H3

The H3 adapter wraps the shared handler with H3's event-handler interface. It keeps the H3Event as the hook context and uses H3's Web request conversion before returning the shared Web response. The application chooses the route location when it mounts this event handler.

References: packages/…/h3.ts• L22-40

Remix

The Remix adapter targets route modules that receive ActionFunctionArgs. It uses args.request as the shared Web request and keeps the full action argument object for hooks. The same handler is exposed as both the route action and loader, which lets the route provide the metadata and upload methods expected by the client protocol.

References: packages/…/remix.ts• L21-39

Runtime contracts

The adapters share a small contract with the router and the client. A correct integration must preserve the route URL and request data at the framework boundary, then return the shared handler's status, headers, and body without changing their meaning.

Router configuration

The route handler receives a FileRouter and optional RouteHandlerConfig. The router names the upload routes. Configuration supplies server-wide values such as the callback URL, development mode, fetch implementation, ingest URL, and the policy for work that continues after the response. These values affect the shared handler rather than a single framework.

References: packages/…/types.ts• L31 packages/…/types.ts• L42-87 packages/…/types.ts• L89-92 packages/…/handler.ts• L103-109

Hook context

The shared handler stores the native adapter arguments for the active request and passes them to route middleware and upload hooks. This gives a Next.js hook a Next request, an Express hook an Express request and response, or a Remix hook its action arguments. The context is the main reason an adapter supplies both a Web request and native framework values.

References: packages/…/handler.ts• L50-52 packages/…/handler.ts• L66-89 packages/…/handler.ts• L420-427 packages/…/handler.ts• L342-364

Response mapping

The shared handler produces a Web Response with an HTTP status, headers, and an optional body. Each adapter must map all three parts to its framework. Next.js Pages and Express perform explicit response writes. Fastify uses its reply object. Next.js App Router, H3, and Remix return the Web response through their native route interfaces.

References: packages/…/handler.ts• L74-101 packages/…/next-legacy.ts• L44-51 packages/…/express.ts• L52-61 packages/…/fastify.ts• L46-52 packages/…/next.ts• L29-39 packages/…/h3.ts• L30-40 packages/…/remix.ts• L29-39

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the adapter's request conversion aligned with the shared handler's need for the route slug, action type, callback headers, body, and origin URL.
  • Keep the mounted endpoint aligned with the URL used by the upload client. Express and H3 depend on the application's mount path. Fastify registers /api/uploadthing directly.
  • Preserve native adapter arguments when changing the hook context. Middleware and upload hooks rely on those values for framework-specific work.
  • Map status, headers, and body together when changing a response bridge. Missing response headers can break version reporting or callback and client behavior.
  • Keep the adapter identifier passed to the shared handler in sync with the runtime when adding or renaming an entry point. UploadThing uses it in server-to-server request metadata.
  • Keep the URL fallback behavior aligned with proxy headers and the explicit callback URL setting. An incorrect origin can prevent development callbacks from reaching the route.

Important failure modes

TriggerConsequenceGuard
A Node-style request has a body that is not JSON or has the wrong content typeThe adapter cannot create the request expected by the shared handler and the client receives a bad-request responseSend JSON with application/json; let the framework body parser or the adapter's stream reader provide an object body
The adapter loses the request path, slug, or action headers during conversionThe shared handler cannot select the file route or callback actionPreserve the native method, URL, headers, and body in the Web Request
A route is mounted at a path different from the client endpointUpload requests never reach the shared handlerMatch the client endpoint to the application mount; note that Fastify registers /api/uploadthing in the adapter
Proxy host or protocol data is missing and no callback URL is configuredGenerated development callback requests can target an invalid originForward x-forwarded-host and x-forwarded-proto, or set an explicit callback URL
Development uses handleDaemonPromise: "await"Handler creation fails with an invalid server configurationUse the development default or a deployment-specific wait mechanism
A response bridge drops the body stream or response headersThe client receives an incomplete upload response or misses protocol metadataMap the Web response status, headers, and body through the framework response API

Key files

FileWhy to read it
packages/…/handler.tsDefines the shared request handler and the upload, metadata, and callback behavior used by every adapter
packages/…/to-web-request.tsDefines the boundary between Node-style requests and the Web Request used by the shared handler
packages/…/types.tsDefines the common file-router and route-handler configuration contract
packages/…/next.tsShows the Next.js App Router entry point
packages/…/next-legacy.tsShows the legacy Next.js Pages API response bridge
packages/…/express.tsShows the Express router and streamed response bridge
packages/…/fastify.tsShows the Fastify route registration and reply mapping
packages/…/h3.tsShows the H3 event-handler boundary
packages/…/remix.tsShows the Remix loader and action boundary