Kind: Interface
Source: packages/common/pipes/file/interfaces/file.interface.ts
Part of: Common
IFile defines the normalized shape of a file handled by the common file pipe utilities. It stores the file MIME type, byte size, and in-memory Buffer content so validation and downstream processing can work with a consistent payload.
Properties
| Property | Type |
|---|---|
mimetype | string |
size | number |
buffer | Buffer |
Diagram
mermaidgraph LR Upload[Incoming file upload] --> IFile[IFile] IFile --> Mime[mimetype: string] IFile --> Size[size: number] IFile --> Content[buffer: Buffer] IFile --> Validation[File validation pipes] Validation --> Processing[Application file processing]
Usage
tsimport { IFile } from '@common/pipes/file/interfaces/file.interface';
function validateImage(file: IFile): void {
if (!file.mimetype.startsWith('image/')) {
throw new Error('Only image files are allowed.');
}
if (file.size > 5 * 1024 * 1024) {
throw new Error('File must not exceed 5 MB.');
}
}
const file: IFile = {
mimetype: 'image/png',
size: 1024,
buffer: Buffer.from('image-content'),
};
validateImage(file);
AI Coding Instructions
- Treat
bufferas the authoritative in-memory file content; do not assume a filesystem path or stream is available. - Validate
mimetypeandsizebefore processing or persisting file data. - Keep
sizealigned with the byte length ofbufferwhen constructingIFileobjects manually. - Use this interface at file-pipe boundaries to normalize upload-provider-specific file objects.
Was this page helpful?