My App
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:

  1. File size: Must not exceed maxAssetSizeMb
  2. Board quota: Total board storage must not exceed maxBoardSizeMb
  3. MIME type: Must be one of the allowed types

Allowed MIME Types

MIME TypeFormat
image/pngPNG
image/jpegJPEG
image/gifGIF
image/webpWebP
image/svg+xmlSVG
application/pdfPDF

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

ConditionError
File too largeAsset size X.XXMB exceeds limit of 25MB
Board quota exceededBoard storage would exceed limit of 100MB
Invalid MIME typeUnsupported file type: application/zip

On this page