# MinIO (https://s3.dimah.dev/docs/providers/minio)



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

## Configuration [#configuration]

Set `forcePathStyle: true` on the S3Client so object URLs format as `http://host:9000/bucket/key`:

```ts title="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 MinIO
  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 CORS configuration [#minio-cors-configuration]

Set the `MINIO_API_CORS_ALLOW_ORIGIN` environment variable on your MinIO server:

```bash
MINIO_API_CORS_ALLOW_ORIGIN=https://your-app.example
```

## Frequently asked questions [#frequently-asked-questions]

<Accordions>
  <Accordion title="Why is my browser upload failing with a network error on localhost?">
    Ensure `S3_ENDPOINT` points to the MinIO API port (typically `9000`), not the web console port (typically `9001`).
  </Accordion>
</Accordions>
