dimah-s3v1.5.5
Bring your own backend

Upload

upload and confirm — presign a single PUT/POST, then verify the object.

  1. upload — your backend returns a presigned URL (POST fields or PUT headers).
  2. The browser uploads directly to S3.
  3. confirm — your backend verifies the object (typically HeadObject) and returns metadata.

Large files: Multipart.

upload does not receive key. Generate it on the server and return it in the presign response. confirm sends that stored key plus the same route.

Presign

Prop

Type

Return all of these fields. fields when method is "POST"; headers when method is "PUT".

Prop

Type

Confirm

Prop

Type

contentLength and metadata are required. eTag and contentType come from HeadObject when available.

Prop

Type

import type {
  UploadPayload,
  UploadPresignResponse,
  ConfirmPayload,
  UploadConfirmResponse,
} from "@dimah-s3/core";

Example

Add these to the defineApi skeleton. Paths are yours — @dimah-s3/server uses /api/s3/presign/upload and /api/s3/presign/upload/confirm.

async function post<T>(url: string, body: unknown): Promise<T> {
  const res = await fetch(url, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(body),
  });
  if (!res.ok) throw new Error(await res.text());
  return res.json();
}

const upload = (payload) => post("/api/files/presign/upload", payload);
const confirm = (payload) => post("/api/files/presign/upload/confirm", payload);

On this page