dimah-s3v1.5.5
Bring your own backend

Bring your own backend

Connect the React client to your existing API.

Implement S3Api with defineApi. Routes, transport, and server framework are up to you. They do not need to match @dimah-s3/server.

Each S3Api method must accept the documented input and return JSON with every field in the response tables. Missing fields break the hooks. Every request includes a required route name. Upload and multipart init do not send key — your backend generates it and returns it.

Input types: Parameters<S3Api["upload"]>. Response types are exported from @dimah-s3/core.

Flows

FlowMethodsDoc
Simple uploadupload → browser uploads to S3 → confirmUpload
DownloaddownloadDownload
DeletedeleteDelete
MultipartinitsignPartcomplete or abort · listParts to resumeMultipart

Skeleton

Merge the methods from each page into one defineApi call:

lib/s3-api.ts
import { defineApi } from "@dimah-s3/react";

export const api = defineApi({
  async upload(payload) {
    /* see Upload */
  },
  async confirm(payload) {
    /* see Upload */
  },
  async download(payload) {
    /* see Download */
  },
  async delete(payload) {
    /* see Delete */
  },
  multipart: {
    async init(payload) {
      /* see Multipart */
    },
    async signPart(payload) {
      /* see Multipart */
    },
    async listParts(payload) {
      /* see Multipart */
    },
    async complete(payload) {
      /* see Multipart */
    },
    async abort(payload) {
      /* see Multipart */
    },
  },
});

On this page