BoardKitBackend
AssetService
File upload with size and type validation
AssetService handles file uploads with validation for size, board storage quota, and MIME type.
Configuration
Asset limits can be configured via BoardModule.register():
BoardModule.register({
// ...
limits: {
maxAssetSizeMb: 25, // max single file (default: 25 MB)
maxBoardSizeMb: 100, // max total per board (default: 100 MB)
},
})Methods
upload
Uploads a file with validation. Throws if validation fails.
async upload(boardId: string, file: Buffer, meta: AssetMeta): Promise<Asset>;interface AssetMeta {
mimeType: string;
sizeBytes: number;
uploadedBy: string;
}Validation checks:
- File size: Must not exceed
maxAssetSizeMb - Board quota: Total board storage must not exceed
maxBoardSizeMb - MIME type: Must be one of the allowed types
Allowed MIME Types
| MIME Type | Format |
|---|---|
image/png | PNG |
image/jpeg | JPEG |
image/gif | GIF |
image/webp | WebP |
image/svg+xml | SVG |
application/pdf |
getUrl
Returns the URL for a stored asset.
async getUrl(storageKey: string): Promise<string>;delete
Deletes an asset from storage.
async delete(storageKey: string): Promise<void>;getBoardUsage
Returns the total storage usage for a board in bytes.
async getBoardUsage(boardId: string): Promise<number>;Error Messages
| Condition | Error |
|---|---|
| File too large | Asset size X.XXMB exceeds limit of 25MB |
| Board quota exceeded | Board storage would exceed limit of 100MB |
| Invalid MIME type | Unsupported file type: application/zip |