Merge pull request #206 from cameronapak/main

docs: add documentation on S3 integration
This commit is contained in:
dswbx
2025-07-19 09:13:20 +02:00
committed by GitHub
5 changed files with 69 additions and 3 deletions

View File

@@ -1 +1,2 @@
tmp/* tmp/*
!tmp/.gitkeep

View File

View File

@@ -4,7 +4,7 @@ title: bknd.config.ts
The central configuration file to extend bknd should be placed in the root of your project, so that the [CLI](/usage/cli#using-configuration-file-bknd-config) can automatically pick it up. It allows to: The central configuration file to extend bknd should be placed in the root of your project, so that the [CLI](/usage/cli#using-configuration-file-bknd-config) can automatically pick it up. It allows to:
* define your database connection centrally * define your database connection centrally
* pass in initial configuration or data seeds when booting the first time * pass in [initial configuration](/usage/database#initial-structure) or [data seeds](/usage/database#seeding-the-database) when booting the first time
* add plugins to the app * add plugins to the app
* hook into system events * hook into system events
* define custom routes and endpoints * define custom routes and endpoints

View File

@@ -16,3 +16,68 @@ on your environment).
The media tools are designed to integrate effortlessly into your workflows, offering scalability The media tools are designed to integrate effortlessly into your workflows, offering scalability
and control without added complexity. and control without added complexity.
### Pre-built support for S3
There are two ways to enable S3 or S3 compatible storage in bknd.
1. Enable via the admin UI.
Simply navigate to the **Media** tab of the bknd admin UI and enable the S3 media support.
Enter your AWS S3-compatible storage Access Key, Secret Access Key, and URL.
This will automatically configure the S3 adapter for you.
**URL Format Examples:**
- **S3**: `https://{bucket}.s3.{region}.amazonaws.com`
- **R2 (Cloudflare)**: `https://{account_id}.r2.cloudflarestorage.com/{bucket}`
2. Enable programmatically.
To enable using a code-first approach, create an [Initial Structure](/usage/database#initial-structure) using the `initialConfig` option in your `bknd.config.ts` file.
```typescript bknd.config.ts
import type { BkndConfig } from "bknd/adapter";
export default {
initialConfig: {
media: {
enabled: true,
adapter: {
type: "s3",
config: {
access_key: "<key>",
secret_access_key: "<secret key>",
url: "<bucket url>"
}
}
}
}
} satisfies BkndConfig;
```
### Local adapter for development
For local development and testing, you can use the local file system adapter. This is particularly useful when working with Node.js environments.
```typescript bknd.config.ts
import { registerLocalMediaAdapter } from "bknd/adapter/node";
import type { BkndConfig } from "bknd/adapter";
// Register the local media adapter
const local = registerLocalMediaAdapter();
export default {
initialConfig: {
media: {
enabled: true,
adapter: local({
path: "./public/uploads", // Files will be stored in this directory
}),
}
}
} satisfies BkndConfig;
```
This configuration will store uploaded files in the specified directory,
making them accessible through your application's public path (in this case)
or at `/api/media/file/{filename}`.

View File

@@ -78,7 +78,7 @@ see [Custom Connection](/usage/database#custom-connection) as a reference.
If the connection object is omitted, the app will try to use an in-memory database. If the connection object is omitted, the app will try to use an in-memory database.
### `initialConfig` ### `initialConfig`
As initial configuration, you can either pass a partial configuration object or a complete one As [initial configuration](/usage/database#initial-structure), you can either pass a partial configuration object or a complete one
with a version number. The version number is used to automatically migrate the configuration up with a version number. The version number is used to automatically migrate the configuration up
to the latest version upon boot. The default configuration looks like this: to the latest version upon boot. The default configuration looks like this: