Typed file uploads for React & Next.js
Presigned S3 uploads, a typed HTTP wire contract, and React hooks. Define a file router on the server — the client hook types itself from it.
npm install @upload-stuff/server @upload-stuff/client// Server — define a typed file routerexport const fileRouter = { avatar: f({ files: ["image/*"], maxFileSize: "4MB" }) .middleware(({ ctx }) => ({ userId: ctx.userId })) .onUploadComplete(({ files }) => ({ url: files[0].publicUrl })) .build(),};// Client — the hook's return type is inferred from the router.// No type annotations, no drift.const { startUpload, isUploading } = useUploadStuff((r) => r.avatar, { onClientUploadComplete: (res) => console.log(res.files),});