Skip to content

Commit 96755c1

Browse files
committed
docs: S3 compatible adapter docs and Cloudflare R2 setup example
AdminForth/1703/make-s3-adapter-support-url-pa
1 parent 3f2fa5d commit 96755c1

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

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

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,61 @@ 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+
```
1864

1965
## Local Storage Adapter
2066

2167
```bash
22-
pnpm i @adminforth/storage-adapter-local
68+
pnpm add @adminforth/storage-adapter-local
2369
```
2470

2571
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)