Kind: Interface
Source: packages/platform-express/multer/interfaces/multer-options.interface.ts
Part of: Platform Express
MulterField defines a named multipart form-data field accepted by NestJS's Multer integration. It is typically used when configuring file upload interceptors that accept multiple named file fields, with maxCount limiting how many files each field may contain.
Properties
| Property | Type |
|---|---|
name | string |
maxCount | number |
Diagram
mermaidgraph LR Client[Multipart Request] --> Interceptor[FileFieldsInterceptor] Interceptor --> Field[MulterField] Field --> Name["name: field identifier"] Field --> MaxCount["maxCount: maximum files"] Interceptor --> Uploads[Uploaded file arrays]
Usage
tsimport { Controller, Post, UploadedFiles, UseInterceptors } from '@nestjs/common';
import { FileFieldsInterceptor } from '@nestjs/platform-express';
import type { MulterField } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
const uploadFields: MulterField[] = [
{ name: 'avatar', maxCount: 1 },
{ name: 'documents', maxCount: 5 },
];
@Controller('uploads')
export class UploadController {
@Post()
@UseInterceptors(FileFieldsInterceptor(uploadFields))
uploadFiles(
@UploadedFiles()
files: {
avatar?: Express.Multer.File[];
documents?: Express.Multer.File[];
},
) {
return {
avatar: files.avatar?.[0],
documents: files.documents ?? [],
};
}
}
AI Coding Instructions
- Use
namevalues that exactly match the multipart form field names sent by clients. - Set
maxCountto the intended per-field upload limit; use1for single-file fields. - Pass
MulterField[]toFileFieldsInterceptorwhen an endpoint accepts several differently named file fields. - Remember that uploaded files are returned as arrays per field, including fields configured with
maxCount: 1. - Configure Multer validation, storage, and file-size limits separately through interceptor options or module configuration.
Was this page helpful?