Skip to content

Commit d72ce3c

Browse files
authored
Merge pull request #671 from devforth/next
Next
2 parents b5cf6b0 + fdc54f5 commit d72ce3c

1 file changed

Lines changed: 79 additions & 3 deletions

File tree

adminforth/documentation/docs/tutorial/06-Adapters/04-storage-adapters.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,91 @@ Used for storing files.
1111
## Amazon S3 Storage Adapter
1212

1313
```bash
14-
pnpm i @adminforth/storage-adapter-amazon-s3
14+
pnpm add @adminforth/storage-adapter-amazon-s3
1515
```
1616

17-
Stores uploaded files in [Amazon S3](https://aws.amazon.com/s3/), providing scalable cloud storage. It can be forked and customized to work with S3-compatible services such as MinIO, Wasabi, or other third-party S3 providers.
17+
Stores uploaded files in [Amazon S3](https://aws.amazon.com/s3/), providing scalable cloud storage.
18+
19+
## S3 compatible adapter
20+
```bash
21+
pnpm add @adminforth/storage-adapter-s3-compatible
22+
```
23+
24+
Provides S3 compatible interface for object storage services such as MinIO, Wasabi, Cloudflare R2 or other third-party S3 providers.
25+
26+
27+
### Cloudflare R2 setup example
28+
29+
This adapter requires key/value adapter. For example, we will be using levelDb adapter.
30+
>‼️Since levelDb is used for storing keys of objects, that should/shouldn't be deleted, so this is important to use docker volume on deployed application, so you will not loose this data after re-deploy
31+
```bash
32+
pnpm add @adminforth/key-value-adapter-leveldb
33+
```
34+
35+
1) Go to the [Cloudflare dashboard](https://dash.cloudflare.com/) and create new bucket. Get bucket URL.
36+
2) Get R2 Access key id and Secret access key
37+
3) Add in the .env file:
38+
```
39+
R2_ACCESS_KEY_ID=your_access_key_id
40+
R2_SECRET_ACCESS_KEY=your_secret_access_key
41+
R2_ENDPOINT_URL=your_bucket_url
42+
R2_BUCKET_NAME=your_bucket_name
43+
R2_BUCKET_REGION=auto
44+
```
45+
4) Setup adapter:
46+
```ts
47+
import LevelDBKeyValueAdapter from '@adminforth/key-value-adapter-leveldb';
48+
49+
new AdminForthAdapterS3CompatibleStorage({
50+
accessKeyId: process.env.R2_ACCESS_KEY_ID as string,
51+
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY as string,
52+
endpoint: process.env.R2_ENDPOINT_URL as string,
53+
bucket: process.env.R2_BUCKET_NAME as string,
54+
region: process.env.R2_BUCKET_REGION as string,
55+
s3ACL: "private",
56+
cleanupKeyValueAdapter: new LevelDBKeyValueAdapter({
57+
dbPath: './cloudflare_r2_storage_keys',
58+
});,
59+
forcePathStyle: true,
60+
cleanupCheckInterval: '30m',
61+
cleanupGracePeriod: '5d'
62+
}),
63+
```
64+
65+
### MinIO setup
66+
67+
1) If you don't have running instanse, then run it with command
68+
```bash
69+
docker run \
70+
-p 9000:9000 \
71+
-p 9001:9001 \
72+
-e MINIO_ROOT_USER=minioadmin \
73+
-e MINIO_ROOT_PASSWORD=minioadmin \
74+
minio/minio server /data --console-address ":9001"
75+
```
76+
2) Create bucket
77+
3) Setup adapter:
78+
```ts
79+
import LevelDBKeyValueAdapter from '@adminforth/key-value-adapter-leveldb';
80+
81+
new AdminForthAdapterS3CompatibleStorage({
82+
accessKeyId: 'minioadmin',
83+
secretAccessKey: 'minioadmin',
84+
endpoint: 'http://localhost:9000',
85+
bucket: 'adminforth-dev-demo',
86+
region: 'us-east-1',
87+
s3ACL: 'private',
88+
cleanupKeyValueAdapter: levelDbAdapter,
89+
forcePathStyle: true,
90+
cleanupCheckInterval: '30m',
91+
cleanupGracePeriod: '5d'
92+
}),
93+
```
1894

1995
## Local Storage Adapter
2096

2197
```bash
22-
pnpm i @adminforth/storage-adapter-local
98+
pnpm add @adminforth/storage-adapter-local
2399
```
24100

25101
Stores files locally on the server filesystem. It is suitable for development or small self-hosted setups, but cloud storage is generally a better production option for reliability and scalability.

0 commit comments

Comments
 (0)