NestJS / ExpressJs参数太多

时间:2018-01-25 14:41:19

标签: node.js express nestjs

我正在尝试将文件发送到NestJS控制器,但不断获得too many parameters异常。我已安装bodyParser并更新了请求大小限制以绕过request too large例外。

main.ts:

import { NestFactory } from "@nestjs/core";
import { ApplicationModule } from "./app/app.module";
import * as express from "express";
import * as bodyParser from "body-parser";

async function bootstrap() {
    const server = express();
    server.use(bodyParser({limit: '50mb'}));

    console.log(server);

    const app = await NestFactory.create(ApplicationModule, server);
    await app.listen(process.env.PORT || 3000);
}
bootstrap();

控制器:

import { Get, Controller, Query, Post, Request } from "@nestjs/common";
import { CloudVisionLogoService } from "./logos.component";

@Controller("logos")
export class LogoRecognitionController {
    public constructor(
        private readonly _logoRecognition: CloudVisionLogoService
    ) {
    }

    @Post()
    public async detectLogos(@Request() req) {
        console.log(req.files[0]);
        // return await this._logoRecognition.detectLogos(imageUri);
    }
}

邮递员请求(未显示,图像的二进制附件):

POST /logos HTTP/1.1
Host: localhost:3000
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Postman-Token: c95da069-c602-58a9-1e05-36456a527f02

undefined

1 个答案:

答案 0 :(得分:2)

以下内容来自body-parser docs:

  

由于它们复杂而且不能处理多部分主体   通常是大自然。对于多部分机构,您可能感兴趣   以下模块:

     

busboy和connect-busboy

     

multiparty和connect-multiparty

     

强大

     

multer

我建议你使用multer套餐,因为它很简单且很多用户都使用它