Field value too long (3184658 characters), use form data

173 Views Asked by At

This is my field in DTO

@IsNotEmpty({ message: 'Nội dung này không được để trống!' })
@IsString()
@MinLength(0, { message: 'Độ dài bài viết không hợp lệ!' })
content: string;

I have not set a maximum limit for this field, but when transmitting a large string of 3184658 characters an error occurred

"statusCode": 400,
"message": "Field value too long",
"error": "Bad Request"

If the error is due to DTO, the error code will usually be 422 (not 400). I tried reconfiguring my middleware but it's not work

app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }));

Because Form-Data. Is there any way to remove the limit for formdata?

1

There are 1 best solutions below

0
Hai Alison On

you need to increase the field data limit in multer module:

MulterModule.registerAsync({
      useFactory: () => ({
        //...your config,
        limits: {
          fieldSize: parseInt(process.env.MAX_FIELD_SIZE), //default 1MB
          //in my case using limit file size and file number
          fileSize: parseInt(process.env.MAX_SIZE_PER_FILE_UPLOAD),
          files: parseInt(process.env.MAX_NUMBER_FILE_UPLOAD),
        },
      }),
    }),