#`@fastify/multipart` Maximum call stack size exceeded

13 messages · Page 1 of 1 (latest)

steel hollow
#

Hi everyone. I'm upgrading my project from 10.X to 11.X and I'm having some problems regarding the new fastify version. I've used to use the @fastify/multipart to handle form-data submition as follows:

import * as fastifyMultipart from '@fastify/multipart';
...
await app.register(fastifyMultipart, {
    addToBody: true,
    attachFieldsToBody: true,
    throwFileSizeLimit: true,
    limits: {
      fieldNameSize: 256,
      fileSize: 100 * 1024 * 1024,
    },
  });

But righ now I'm getting the following error when I submit a file trought form-data:

ERROR [ExceptionsHandler] RangeError: Maximum call stack size exceeded
    
at ValidationPipe.stripProtoKeys (C:\Users\predo\git\gupchat-api\node_modules\@nestjs\common\pipes\validation.pipe.js:165:19)

Does any one know how i can fix that?

upper mirage
#

so this issue arises due to a known conflict between the attachFilesToBody: true option in @fastify/multipart and nestjs's global validation pipeline

#

the conflict leads to an infinite loop during validation, resulting in the stack overflow error

#

in my opinion, to mitigate this issue, you consider removing the attachFilesToBody: true option during the registeration of @fastify/multipart

#

however, be aware that without this option, the form data wont be automatically attached to the request body, which means the validation pipeline might not function as intended

#

in such cases, you may need to manually handle the parsing and validation of form data

#

and from my experience, i'd like to say there is other way to fix that issue

#

if removing attachFilesToBody isnt feasible for your application's requirements, you might explore alternative methods for handling file uploads and form data in nestjs with fastify

#

for instance, using the @blzaity/nest-file-fastify package can simplify file handling in nestjs applications that utilize fastify

#

this package integrates seamlessly and offers a more straightforward approach to managing file uploads

steel hollow