Skip to content

Commit 77e1d44

Browse files
authored
Merge pull request #319 from devforth/local-storage-docs
docs: add HEAD method to allowed methods in documentation and enhance…
2 parents 4990cd5 + ef71c92 commit 77e1d44

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

adminforth/documentation/blog/2024-10-01-ai-blog/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Go to bucket settings, Permissions, Object ownership and select "ACLs Enabled" a
7272
"*"
7373
],
7474
"AllowedMethods": [
75+
"HEAD",
7576
"PUT"
7677
],
7778
"AllowedOrigins": [

adminforth/documentation/docs/tutorial/07-Plugins/05-upload.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Leave all settings unchanged (ACL Disabled, Block all public access - checked)
3030
"*"
3131
],
3232
"AllowedMethods": [
33+
"HEAD",
3334
"PUT"
3435
],
3536
"AllowedOrigins": [
@@ -275,7 +276,33 @@ If for example your domain is `my-domain.com` and you bucket has name `static.my
275276
276277
Also you will have to enable static website hosting in your bucket settings and set index.html and error.html to empty strings.
277278
278-
### S
279+
### Using local storage adapter
280+
281+
The local storage adapter saves files directly on the server’s filesystem and serves them through Express routes. It supports both public and private modes (with presigned URLs).
282+
283+
```
284+
npm i @adminforth/storage-adapter-local --save
285+
```
286+
287+
```ts title="./index.ts"
288+
import LocalStorageAdapter from '@adminforth/storage-adapter-local';
289+
290+
new UploadPlugin({
291+
storageAdapter: new LocalStorageAdapter({
292+
fileSystemFolder: "./db/uploads",
293+
adminServeBaseUrl: "static/source",
294+
mode: "public", // or "private"
295+
signingSecret: process.env.ADMINFORTH_SECRET,
296+
}),
297+
pathColumnName: 'apartment_image',
298+
allowedFileExtensions: ['jpg', 'jpeg', 'png', 'gif', 'webm', 'webp'],
299+
maxFileSize: 1024 * 1024 * 20, // 20 MB
300+
filePath: ({originalFilename, originalExtension, contentType}) =>
301+
`aparts/${new Date().getFullYear()}/${uuid()}-${originalFilename}.${originalExtension}`,
302+
})
303+
```
304+
> adminServeBaseUrl defines the public path prefix. If your AdminForth base URL is /admin, files will be accessible under /admin/static/source/<key>.
305+
279306
280307
281308
## Image generation
@@ -391,17 +418,19 @@ plugins: [
391418
...
392419
new UploadPlugin({
393420
pathColumnName: 'apartment_source',
394-
storageAdapter: (sourcesAdapter = new AdminForthStorageAdapterLocalFilesystem({
421+
storageAdapter: (sourcesAdapter = new LocalStorageAdapter({
395422
fileSystemFolder: "./db/uploads",
396423
mode: "public",
424+
adminServeBaseUrl: "static/source",
397425
signingSecret: process.env.ADMINFORTH_SECRET, // secret used to generate presigned URLs
398426
}), sourcesAdapter),
399427
}),
400428
new UploadPlugin({
401429
pathColumnName: 'apartment_image',
402-
storageAdapter: new AdminForthAdapterLocalFilesystem({
430+
storageAdapter: new LocalStorageAdapter({
403431
fileSystemFolder: "./db/uploads",
404432
mode: "public",
433+
adminServeBaseUrl: "static/source",
405434
signingSecret: process.env.ADMINFORTH_SECRET, // secret used to generate presigned URLs
406435
}),
407436
generation: {

0 commit comments

Comments
 (0)