Static Asset Component
StaticAssetComponent turns one declaration into a REST controller for the files in one bucket, on disk or S3-compatible storage. You write the entry; it writes the routes.
import { DiskHelper } from '@venizia/ignis-helpers';
import type { TStaticAssetComponentOptions } from '@venizia/ignis/static-asset';
export const options: TStaticAssetComponentOptions = {
documents: {
basePath: '/documents',
bucket: 'documents',
helper: new DiskHelper({ basePath: './app_data' }),
serverUpload: { use: true },
directUpload: { use: false },
metaLink: { use: false },
},
};That registers upload, stream, download, list and delete under /documents. Every feature is a switch: { use: false } or { use: true, ...options }. Leave one out and the entry does not compile, so nothing is on or off by accident.
WARNING
Every route is open until you set auth on the entry. Set it before the entry faces users.
IMPORTANT
The component never creates the bucket. Create it once before you start. See Create the bucket.
Two ways a file arrives
serverUpload | directUpload | |
|---|---|---|
| Path | browser, then your app, then storage | browser, then storage (your app signs a permission) |
| Route | POST /objects | POST /upload-policy, then POST /upload-validate (with a validation), then POST /upload-commit |
| Your process sees the bytes | yes, the whole body in memory | no |
| Storage | disk or S3 | S3 only (a signed POST policy) |
Needs a keyPrefix | no | yes |
| Check the file before accepting it | in your own code after the upload | validation, run once at upload-validate; commit takes the token it returns |
| Good for | images, documents, anything small | video, large files, imports that must be checked first |
An entry can turn either one on, both, or neither.
Start from one of the three complete setups, then read Server upload or Direct upload.
How it works
- One entry, one controller.
TStaticAssetComponentOptionsis a record. Each key is an entry with its ownbasePath, bucket, helper and auth. The controller's name comes from the key (staticAssetbecomesStaticAssetController) unless you setname. - One bucket per entry.
bucketis required and never appears in a URL. To serve several buckets, declare several entries. There are no routes to list, create or delete buckets. - The helper is the storage. Pass a
DiskHelperor aBunS3Helper. The helper declares its ownstorageType, so there is nostoragefield. - Routes are named and switchable.
routes.<key>turns a built-in route off ({ use: false }) or on with overrides ({ use: true, ... }). See the route table. - MetaLink is a table you own. Switch
metaLinkon and every upload writes a row; switch it off and nothing is recorded.
Pages
| Page | Read it to |
|---|---|
| Getting started | copy a complete declaration |
| Server upload | upload through your app, with labels and a MetaLink row |
| Direct upload | upload straight to storage, validate, then commit |
| Security | close what is open, and run the flow safely |
| Usage | read, list, delete and track objects |
| Configuration reference | every option, route, key and helper |
| Error reference | every code and what to do about it |
| Migration | move from the old controller and extra shape |
See also
- Why a policy and not a presigned PUT - the design behind direct upload.
- Storage helpers -
DiskHelper,BunS3Helperand theIStorageHelpercontract.
Files: