Kerry Ritter
Kerry Ritter

Reputation: 1187

NestJS/ExpressJs too many parameters

I am trying to send a file to a NestJS controller but keep getting a too many parameters exception. I have installed bodyParser and updated the request size limit to get around a request too large exception.

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();

Controller:

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);
    }
}

Postman request (not shown, binary attachment of image):

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

Upvotes: 0

Views: 2190

Answers (1)

YouneL
YouneL

Reputation: 8351

The following is from body-parser docs:

This does not handle multipart bodies, due to their complex and typically large nature. For multipart bodies, you may be interested in the following modules:

busboy and connect-busboy

multiparty and connect-multiparty

formidable

multer

I suggest you to use multer package because it's easy and many users use it

Upvotes: 2

Related Questions