We are migrating from express to fastify in our nestJS application. The multipart form data(json body not files) which were supported in post controllers are not working after migration. We have typeorm, swagger as well plugged in. Any help is appreciated. Please find below code,
async function bootstrap() {
const { AppModule } = require('./app.module');
const adapter = new FastifyAdapter({
logger: true,
});
await adapter.register(fastifyMultipart, {
limits: {
fieldNameSize: 100, // Max field name size in bytes
fieldSize: 1000000, // Max field value size in bytes
fields: 10, // Max number of non-file fields
fileSize: 100, // For multipart forms, the max file size
files: 1, // Max number of file fields
headerPairs: 2000, // Max number of header key=>value pairs
}
});
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
adapter,
);
await app.init();
app.useGlobalPipes(new ValidationPipe());
app.use(multer({ dest: './public/uploads/' }).single('file'));
const config = new DocumentBuilder()
.setTitle('Test API')
.setDescription('Test Identity management')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('testapi', app, document);
await app.listen(process.env.PORT, '0.0.0.0');
}
And the controller code is,
@Post('/Test/V2')
@ApiOperation({ description: 'test' })
@ApiResponse({ status: 200 })
public async Test(@Request() req, @Body() requestDto: RequestDto, @Response() response) {
}
Library versions are below,
@nestjs/axios: "0.0.3",
@nestjs/common: "^8.2.0",
@nestjs/core: "^8.2.0",
@nestjs/jwt: "^8.0.0",
@nestjs/passport: "^8.0.1",
@nestjs/platform-express: "^8.2.0",
@nestjs/platform-fastify: "^8.2.0",
@nestjs/swagger: "^5.1.4",
@nestjs/testing: "^8.2.0",
@nestjs/typeorm": "^8.0.2"