Skip to content

Documentation · IGNIS

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.

ts
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 ​

serverUploaddirectUpload
Pathbrowser, then your app, then storagebrowser, then storage (your app signs a permission)
RoutePOST /objectsPOST /upload-policy, then POST /upload-validate (with a validation), then POST /upload-commit
Your process sees the bytesyes, the whole body in memoryno
Storagedisk or S3S3 only (a signed POST policy)
Needs a keyPrefixnoyes
Check the file before accepting itin your own code after the uploadvalidation, run once at upload-validate; commit takes the token it returns
Good forimages, documents, anything smallvideo, 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. TStaticAssetComponentOptions is a record. Each key is an entry with its own basePath, bucket, helper and auth. The controller's name comes from the key (staticAsset becomes StaticAssetController) unless you set name.
  • One bucket per entry. bucket is 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 DiskHelper or a BunS3Helper. The helper declares its own storageType, so there is no storage field.
  • 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 metaLink on and every upload writes a row; switch it off and nothing is recorded.

Pages ​

PageRead it to
Getting startedcopy a complete declaration
Server uploadupload through your app, with labels and a MetaLink row
Direct uploadupload straight to storage, validate, then commit
Securityclose what is open, and run the flow safely
Usageread, list, delete and track objects
Configuration referenceevery option, route, key and helper
Error referenceevery code and what to do about it
Migrationmove from the old controller and extra shape

See also ​

Files: