My App
BoardKitBackend

AssetStorage Interface

Abstract storage interface for file uploads

AssetStorage is the abstract class for storing and retrieving uploaded files (images, PDFs).

abstract class AssetStorage {
    abstract upload(boardId: string, file: Buffer, meta: AssetMeta): Promise<Asset>;
    abstract getUrl(storageKey: string): Promise<string>;
    abstract delete(storageKey: string): Promise<void>;
    abstract getBoardUsage(boardId: string): Promise<number>;
}

AssetMeta

interface AssetMeta {
    mimeType: string;
    sizeBytes: number;
    uploadedBy: string;
}

Methods

upload

Stores a file and returns an Asset record with the generated storageKey.

ParameterTypeDescription
boardIdstringBoard this asset belongs to
fileBufferRaw file data
metaAssetMetaFile metadata

getUrl

Returns a URL for accessing the stored file. This could be a signed URL (S3), a local file path, or any retrieval mechanism.

delete

Removes a file from storage by its storageKey.

getBoardUsage

Returns the total storage usage for a board in bytes. Used by AssetService to enforce board-level quotas.

Available Implementations

ImplementationDescription
LocalAssetAdapterStores files on the local filesystem
S3AssetAdapterStores files in Amazon S3 or compatible storage
InMemoryAssetStorageIn-memory storage for testing

Implementing a Custom Adapter

import { AssetStorage, type AssetMeta } from '@hfu.digital/boardkit-nestjs';
import type { Asset } from '@hfu.digital/boardkit-core';
import { randomUUID } from 'crypto';

class MyAssetStorage extends AssetStorage {
    async upload(boardId: string, file: Buffer, meta: AssetMeta): Promise<Asset> {
        const storageKey = `${boardId}/${randomUUID()}`;
        // Store file in your preferred storage system
        await myStorage.put(storageKey, file);

        return {
            id: randomUUID(),
            boardId,
            mimeType: meta.mimeType,
            sizeBytes: meta.sizeBytes,
            storageKey,
            uploadedBy: meta.uploadedBy,
            createdAt: new Date().toISOString(),
        };
    }

    async getUrl(storageKey: string): Promise<string> {
        return myStorage.getSignedUrl(storageKey);
    }

    async delete(storageKey: string): Promise<void> {
        await myStorage.delete(storageKey);
    }

    async getBoardUsage(boardId: string): Promise<number> {
        return myStorage.getTotalSize(boardId);
    }
}

On this page