next.js: NextJS 13.4.2 formidable not working.
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Home Single Language
Binaries:
Node: 20.2.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 13.4.4-canary.0
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
npx create-next-app@latest
To Reproduce
export async function POST(req) {
try {
const form = new formidable.IncomingForm();
form.parse(req, (err, fields, file) => {
console.log('Successfully worked.........');
// Do something with the fields but Nextjs 13.4.2 in this fields not worked. Not showing this data in this field.
});
return new Response(JSON.stringify({success: "Successful"}))
} catch (err) {
return new Response(JSON.stringify({error: "Server Side Error !"}), {
status: 500
})
}
}
Describe the Bug
When i handle formData with the formidable npm package but formidable not working properly. I am trying another packege like busboy, multiparty npm packge but all of this are not working. please solve this problem. I’m stuck in this problem 1 week.
Expected Behavior
I want to handle my formData. now I used formidable formData parser, but not working this.
Another suggestion: NextJS API request and response Object will do customize like express JS.
Which browser are you using? (if relevant)
Microsoft Edge Version 112.0.1722.68 (Official build) (64-bit)
How are you deploying your application? (if relevant)
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 10
- Comments: 23 (1 by maintainers)
Hi, i finally was able to upload a file in the new app router, but i did use “fs” not “formidable”, i guess it’s a “formidable” issue maybe it’s not compatible with the new app router!! but anyway here’s my last version hope it helps.
Now i’m using nextjs 13.4.4 but i think it may work for older versions.
File : /app/api/uploadv2/route.ts
i was having the same issue because i’m using /app/api/upimage/route.ts, for almost a week and searched everywhere, but no solution worked, but when i tried the old method in /pages/api/uploadfile.ts it worked straight away, don’t know if it’s a bug or we are doing it wrong but i’m going to the share both version and hope it helps
I’m using : “formidable”: “3.2.5” “next”: “13.4.3”
File : /app/uploader/page.tsx
this code is working and it’s in
File : /pages/api/uploadfile.ts
But this code gives me the error ‘TypeError: req.on is not a function’
File : /app/api/upimage/route.ts
Same problem
Awesome, glad you were able to get this resolved, your solution looks amazing and a great approach. 🎊 🎉
I solved it for you، but I didn’t use forimdible scripts، but I first downloaded the file to base64، then created an image using the node-base64-image library، which works.
Can we conclude formidable is a no-no for the new next >13?