HTTP

Upload to any endpoint that accepts files.

import { httpAdapter } from "@uploadcn/core"

const adapter = httpAdapter<{ id: string; url: string }>({
  url: "/api/files",
  fieldName: "file",
  fields: (item) => ({ folder: String(item.meta.folder ?? "inbox") }),
  headers: async () => ({ authorization: `Bearer ${await getToken()}` }),
})

Sends multipart/form-data by default; body: "binary" sends the raw file with its MIME type (useful for PUT endpoints). The response is parsed as JSON when possible.

Prop

Type

Example: Next.js route handler

app/api/files/route.ts
export async function POST(request: Request) {
  const form = await request.formData()
  const file = form.get("file") as File
  const url = await saveSomewhere(file)
  return Response.json({ url })
}

Proxying files through your server is simple but costs bandwidth and is limited by platform body-size limits (4.5 MB on Vercel functions). Prefer presigned uploads for large files.

On this page