Does formidable support the Nextjs frame
talonshi opened this issue · comments
Now I'm trying using the IncomingForm from formidable in my NestJs work.
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 (likemultiples
). It's also recommended to NOT use the class way and theIncomingForm
class, that's deprecated for years - just use the default exported functionimport formidable from 'formidable';
and then pass itoptions
, likeformidable({ 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...