📁 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
| Task | Start with | Contract |
|---|---|---|
| Generate an object ID and signed upload URL | generateFileUploadUrl | generateFileUploadUrl |
| Generate an avatar upload URL | generateSignedAvatarUploadUrl | generateSignedAvatarUploadUrl |
| Generate a signed download or delete URL | generateSignedDownloadUrl or generateSignedDeleteUrl | generateSignedDownloadUrl or generateSignedDeleteUrl |
| Delete a stored object | deleteFile | deleteFile |
| Expose a stored file safely | normalizeFile | normalizeFile |
| Validate an image or generic upload request | File Storage schemas | File Storage schemas |
Reference map
| Page | Purpose |
|---|---|
| Blocks | Result-returning storage operations and error contract. |
| Schemas | Upload query parameters and 200 response definitions. |
Related modules
File Storage driver configures the Google Cloud Storage implementation. Profile, Organization, Product, and Chat compose these blocks and schemas into public endpoints.