Skip to content
Files SDK
Esc
navigateopen⌘Jpreview

Nitro

Mount the Files gateway in a Nitro (or Nuxt server) route. Marshals the h3 event into a Web Request and returns the Response for Nitro to flush.

files-sdk/nitro mounts a createFilesRouter in a Nitro route (and therefore Nuxt server routes). Nitro’s h3 event carries the Node request as event.node.req, so the binding marshals it into the Web Request the gateway speaks and returns the Web Response for Nitro to flush — hiding the toWebRequest(event) step. A client disconnect is wired through to abort the upstream read on a proxied download.

import { createFiles } from "files-sdk";
import { s3 } from "files-sdk/s3";
import { createFilesRouter } from "files-sdk/api";
import { createRouteHandler } from "files-sdk/nitro";

const router = createFilesRouter({
  files: createFiles({ adapter: s3({ bucket: "uploads" }) }),
  allowedOrigins: ["https://app.example.com"],
  authorize: async ({ req }) => {
    /* throw to deny, or return a per-user constraint — see /ui/server/authorization */
  },
});

// In Nuxt, put this at server/routes/api/files.ts.
export default defineEventHandler(createRouteHandler(router));

See the gateway options for the full configuration and the authorize model for locking it down.

Was this page helpful?