Skip to main content
Version: 0.13.0 (Previous)

📁 File Storage

File Storage exports reusable signed-URL, deletion, and file-normalization blocks. It is not a mountable service and defines no routes, features, handlers, or validators.

Start here

Supply a FileStorageDriver to each file-operation block. The bundled driver provides deleteFile, generateSignedDeleteUrl, generateSignedDownloadUrl, and generateSignedUploadUrl; its default signed-URL lifetime is 900 seconds unless signedUrlExpiresInSeconds is supplied. Its upload URLs sign the supplied Content-Type and exact Content-Length; use the exported schemas to apply endpoint-level MIME allow-lists and the 10 MB request limit when composing upload routes.

import {blocks, drivers} from '@nodeblocks/backend-sdk';

const fileStorageDriver = drivers.createFileStorageDriver(process.env.GCP_PROJECT_ID!, process.env.GCP_BUCKET_NAME!);

const result = await blocks.generateFileUploadUrl(fileStorageDriver, 'image/png', 512_000);

if (result.isErr()) {
throw result.error;
}

const {objectId, url} = result.value;

The driver factory is synchronous and uses Google Application Default Credentials. The returned Result contains a generated object ID and signed URL on success; callers must handle an error result before exposing a URL.

Common tasks

TaskStart withContract
Generate an object ID and signed upload URLgenerateFileUploadUrlgenerateFileUploadUrl
Generate an avatar upload URLgenerateSignedAvatarUploadUrlgenerateSignedAvatarUploadUrl
Generate a signed download or delete URLgenerateSignedDownloadUrl or generateSignedDeleteUrlgenerateSignedDownloadUrl or generateSignedDeleteUrl
Delete a stored objectdeleteFiledeleteFile
Expose a stored file safelynormalizeFilenormalizeFile
Validate an image or generic upload requestFile Storage schemasFile Storage schemas

Reference map

PagePurpose
BlocksResult-returning storage operations and error contract.
SchemasUpload query parameters and 200 response definitions.

File Storage driver configures the Google Cloud Storage implementation. Profile, Organization, Product, and Chat compose these blocks and schemas into public endpoints.