FormData doesn't work properly on node.js
See original GitHub issueDescribe the bug
I actually spent a lot of time debugging if this was a problem with axios, form-data, node or my framework. I narrowed it down to form-data. It actually works properly using the default FormData provided by the browser. But the thing is I need it running with node. I tried parsing it with formidable, nestjs parser and adonisjs v5 parser. All of them work properly using native formdata.
How to reproduce
Just send any FormData with axios, fetch to an endpoint that will print what you receive. It will print out something like this:
{
"----------------------------007181389194487799053447\r\nContent-Disposition: form-data; name": "\"f\"\r\n\r\nt\r\n----------------------------007181389194487799053447--\r\n"
}
Since fetch is not native to node.js, I’m using axios for my test script:
import FormData from "form-data";
import axios from "axios";
const f = new FormData();
f.append("f", "t");
axios.post("http://0.0.0.0:3333/", f).then((data) => console.log(data.data)).catch((e) => console.warn(e));
Issue Analytics
- State:
- Created 2 years ago
- Reactions:15
- Comments:12
Top Results From Across the Web
node.js - Form Data doesn't show correctly when I send it via ...
Form Data doesn't show correctly when I send it via Fetch with Node & Muller & Mongoose & GirdFS ; And what error...
Read more >FormData doesn't work properly on node.js - Bountysource
I narrowed it down to form-data. It actually works properly using the default FormData provided by the browser. But the thing is I...
Read more >FormData is not defined Error in JavaScript | bobbyhadz
The "FormData is not defined Error" error occurs when we try to use the FormData() constructor on the server side, most commonly in...
Read more >FormData - Web APIs - MDN Web Docs - Mozilla
Chrome Edge
FormData Full support. Chrome5. Toggle history Full support. Edge12. Toggl...
@@iterator Full support. Chrome50. Toggle history Full support. Edge18. Toggl...
FormData() constructor Full support....
Read more >Can't upload a file from node.js to my route, getting empty ...
as obviously it is not reading the correct file that you are trying to upload. So use console.log and make sure that that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Thymas1 I ended up working with native node.js libraries and it’s just as easy:
I’m not sure if this covers all of the use cases that form-data solves, but for me this was enough (and removed a dependency, to boot).
Try adding
"Content-Length": formdata.getLengthSync()
in headers, that solved it for me.