dimah-s3v1.5.11
Providers

MinIO

Self-hosted S3 storage with local path-style addressing and server CORS.

MinIO is a lightweight, self-hosted S3-compatible object store.

Configuration

For the local host-and-port endpoint below, set forcePathStyle: true so object URLs use the http://host:9000/bucket/key form:

lib/s3.ts
import { S3Client } from "@aws-sdk/client-s3";
import { dimahS3, route } from "@dimah-s3/server";

export const awsS3 = new S3Client({
  region: "us-east-1",
  endpoint: process.env.S3_ENDPOINT || "http://localhost:9000",
  forcePathStyle: true, // Required for this host-and-port setup
  credentials: {
    accessKeyId: process.env.S3_ACCESS_KEY_ID || "minioadmin",
    secretAccessKey: process.env.S3_SECRET_ACCESS_KEY || "minioadmin",
  },
});

export const s3 = dimahS3({
  client: awsS3,
  bucket: "my-bucket",
  routes: {
    avatar: route({
      upload: {
        fileTypes: ["image/*"],
        maxFileSize: 2 * 1024 * 1024,
      },
    }),
  },
});

MinIO can also use virtual-hosted bucket URLs when DNS and TLS are configured for bucket subdomains; in that setup, forcePathStyle is not required.

MinIO CORS configuration

Set the MINIO_API_CORS_ALLOW_ORIGIN environment variable on your MinIO server:

MINIO_API_CORS_ALLOW_ORIGIN=https://your-app.example

Frequently asked questions

On this page