我们正在迁移自express
to fastify
in our nestJS
应用。这multipart form data
后置控制器中支持的(json 正文而不是文件)在迁移后不起作用。我们有typeorm
, swagger
也已插入。如有任何帮助,我们将不胜感激。请找到下面的代码,
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');
}
控制器代码是,
@Post('/Test/V2')
@ApiOperation({ description: 'test' })
@ApiResponse({ status: 200 })
public async Test(@Request() req, @Body() requestDto: RequestDto, @Response() response) {
}
库版本如下,
@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"