alepha@docs:~/docs/packages/alepha/api$
cat files.md | pretty2 min read
Last commit:
#Alepha - Api Files
#Installation
Part of the alepha package. Import from alepha/api/files.
npm install alepha
#Overview
File storage with metadata: the $storage primitive plus the endpoints,
querying and retention that a database makes possible.
Declare a place to keep files with $storage. Every upload writes a files
row next to the blob, which is what powers paginated listing, TTL expiry,
tags, checksums and creator tracking.
ts
1class Media {2 avatars = $storage({ mimeTypes: ["image/png"], maxSize: 2 });3}4 5const stored = await this.avatars.upload(file, { user });6stored.id; // hand this to GET /api/files/:id
Features:
$storageprimitive with MIME/size constraints and default TTL- Upload/download HTTP endpoints, ETag-aware
- Paginated, filterable file queries
- TTL-based expiration swept by
system.files.purge-deleted - Storage statistics for the admin UI
Blobs without a database are a FileStorageProvider concern - see
alepha/bucket.
#API Reference
#Primitives
$storage- Declares a named, constrained place to keep files.
#Providers
DefaultStorage- Thedefaultstorage.FileAccessProvider- Authorization policy for file reads served throughFileController.streamFile.StorageMultipartCapProvider- Lets the targeted$storagedecide how many bytes a request may carry.
#Environment Variables
Environment variables used to configure this module. These can be set in your .env file or through your deployment configuration.
| Variable | Type | Default | Description |
|---|---|---|---|
FILES_MAX_TOTAL_SIZE |
number | - | Most megabytes all stored files may add up to, every storage together. 0 is unlimited. |
FILES_MAX_USER_SIZE |
number | - | Most megabytes the uploads of one user may add up to, every storage together. 0 is unlimited. |