node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does formidable support the Nextjs frame

talonshi opened this issue · comments

Now I'm trying using the IncomingForm from formidable in my NestJs work.

企业微信截图_16716800946368

I wanna use form.parse function to receive the form-data request from the fronted-end, and my code was supposed to output the files, but it wasn't.

Had already checked the readme file, which the Express and Koa usage is recorded, while there isn't nestjs instruction.

How can I use form.parse function in Nest.js

Did you disable the body parser from Next.js?
In your route file add this:

export const config = {
  api: {
    bodyParser: false,
  },
}

@talonshi NestJS or NextJS? They 2 different things.

All you have to pass us (to the form.parse() method) is the original Nodejs Request stream, and the request headers (well, that's derived by us from the original request stream).

If it's Nextjs, @gauthier-th might be right. I remember seeing some workaround like that.

@talonshi what version you are using? And please DO NOT pass options through the instance (like you passed keepExtensions), pass it to the options object (like multiples). It's also recommended to NOT use the class way and the IncomingForm class, that's deprecated for years - just use the default exported function import formidable from 'formidable'; and then pass it options, like formidable({ uploadDir: './foo', multiples: false, keepExtensions: true }).

@talonshi NestJS or NextJS? They 2 different things.

All you have to pass us (to the form.parse() method) is the original Nodejs Request stream, and the request headers (well, that's derived by us from the original request stream).

If it's Nextjs, @gauthier-th might be right. I remember seeing some workaround like that.

@talonshi what version you are using? And please DO NOT pass options through the instance (like you passed keepExtensions), pass it to the options object (like multiples). It's also recommended to NOT use the class way and the IncomingForm class, that's deprecated for years - just use the default exported function import formidable from 'formidable'; and then pass it options, like formidable({ uploadDir: './foo', multiples: false, keepExtensions: true }).

Okay it's my fault..There was an interceptor named @uploadedfiles() in my controller. When I removed that interceptor, this function worked...