Files connector
GitHubPersists file metadata and delegates direct or presigned S3 uploads to S3Client for the Form upload flow.
Installation
bash
pnpm dlx shadcn@latest add @cs/files-connectorUsage
tsx
import { FilesConnector } from "@/lib/cs/files-connector"tsx
const filesConnector = new FilesConnector({
createDbFile,
findDbFile,
deleteDbFile,
s3Client,
})API Reference
CreateFileParams
Input used to create a persisted file and optionally upload its content.
tsx
type CreateFileParams = {
/** Original filename. */
name: string
/** File MIME type. */
type: string
/** Content to upload, or `null` to create a presigned upload URL. */
content: Buffer | null
/** Identifier of the user who created the file. */
createdBy: number
/** Optional identifier in the related database table. */
remoteId?: number
/** Related database table identified by `remoteId`. */
remoteType?: RemoteType
}ConnectorFile
Persisted file metadata with an optional presigned upload URL.
tsx
type ConnectorFile = {
/** Database identifier. */
id: number
/** Original filename. */
name: string
/** File MIME type. */
type: string
/** Storage path. */
path: string
/** Generated public file identifier. */
uuid: string
/** Identifier of the user who created the file. */
userId: number
/** Optional identifier in the related database table. */
remoteId: number | undefined
/** Related database table. */
remoteType: string | undefined
/** Creation timestamp. */
createdAt: Date
/** Presigned URL used to upload content directly, when requested. */
uploadUrl: string | null
}