mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
Merge pull request #206 from cameronapak/main
docs: add documentation on S3 integration
This commit is contained in:
3
app/__test__/_assets/.gitignore
vendored
3
app/__test__/_assets/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
tmp/*
|
||||
tmp/*
|
||||
!tmp/.gitkeep
|
||||
0
app/__test__/_assets/tmp/.gitkeep
Normal file
0
app/__test__/_assets/tmp/.gitkeep
Normal 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:
|
||||
* 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
|
||||
* hook into system events
|
||||
* define custom routes and endpoints
|
||||
|
||||
@@ -16,3 +16,68 @@ on your environment).
|
||||
|
||||
The media tools are designed to integrate effortlessly into your workflows, offering scalability
|
||||
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}`.
|
||||
|
||||
@@ -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.
|
||||
|
||||
### `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
|
||||
to the latest version upon boot. The default configuration looks like this:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user