ResourcefulBinaryType
The ResourcefulBinaryType class provides validation for base64-encoded binary data. It's designed for storing files, images, and other binary content as strings.
For complete API reference, see ResourcefulBinaryType.
Basic Usage
typescript
import { ResourcefulBinaryType } from '@nhtio/lucid-resourceful/definitions'
const fileType = ResourcefulBinaryType({
minLength: 1,
maxLength: 1048576 // 1MB base64 encoded
})Common Patterns
typescript
class Attachment extends compose(BaseModel, withResourceful({ name: 'Attachment' })) {
// Small image or document
@resourcefulColumn.binary({
type: ResourcefulBinaryType({
minLength: 1,
maxLength: 5242880, // 5MB base64
writeOnly: true // Don't return binary data in responses
}),
nullable: true
})
declare fileData: Buffer | null
// Thumbnail image
@resourcefulColumn.binary({
type: ResourcefulBinaryType({
minLength: 1,
maxLength: 131072, // 128KB base64
nullable: true
})
})
declare thumbnail: Buffer | null
}Configuration
minLength: number- Minimum base64 string lengthmaxLength: number- Maximum base64 string length
Best Practices
- Use for small binary files only
- Consider file storage services for large files
- Mark as writeOnly to avoid returning in responses
- Set appropriate size limits