Support other FormData implementations
See original GitHub issueIs your feature request related to a problem? Please describe.
It’s related to the problem of sending multipart/form-data with Axios on Node.js
Describe the solution you’d like
I would like to be able to do
const axios = require('axios');
const { FormData } = require('formdata-node');
const form = new FormData();
axios.post('http://localhost:8888', form)
Describe alternatives you’ve considered
N/A
Additional context
got recommends using formdata-node. Axios recommends form-data.
I would like to use formdata-node with both because I want to use both got and Axios and I don’t want people reading the code to need to notice that there’s two different libraries used for FormData. Also formdata-node has a table saying that form-data’s FormData doesn’t have a bunch of methods that the browser’s does. I tried using formdata-node with Axios
cd /tmp
mkdir axios-form-test
cd axios-form-test
npm init -y
npm install axios
npm install formdata-node
node
const axios = require('axios');
const { FormData } = require('formdata-node');
const form = new FormData();
form.append('my_field', 'my value');
form.append('my_other_field', 'my second value');
axios.post('http://localhost:8888', form)
and got an error
Uncaught:
Error: Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream
    at createError (/private/tmp/axios-test/node_modules/axios/lib/core/createError.js:16:15)
    at dispatchHttpRequest (/private/tmp/axios-test/node_modules/axios/lib/adapters/http.js:98:23)
    at new Promise (<anonymous>)
    at httpAdapter (/private/tmp/axios-test/node_modules/axios/lib/adapters/http.js:48:10)
    at dispatchRequest (/private/tmp/axios-test/node_modules/axios/lib/core/dispatchRequest.js:58:10)
    at Axios.request (/private/tmp/axios-test/node_modules/axios/lib/core/Axios.js:108:15)
    at Axios.<computed> [as post] (/private/tmp/axios-test/node_modules/axios/lib/core/Axios.js:140:17)
    at Function.wrap [as post] (/private/tmp/axios-test/node_modules/axios/lib/helpers/bind.js:9:15) {
  config: { [...]
Issue Analytics
- State:
- Created a year ago
- Comments:8 (1 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
FormData - Web APIs | MDN
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 >FormData
FormData objects are used to capture HTML form and submit it using fetch or another network method. We can either create new FormData(form)...
Read more >REST Up: Consuming a Multipart/Form-Data REST Method ...
In this blog post, OutSystems MVP Killian Hekhuis explores what a multipart/form-data is and how to consume it when using a low-code ...
Read more >form-data
var FormData = require('form-data'); var http = require('http'); var form = new FormData(); http.request('http://nodejs.org/images/logo.png', ...
Read more >How to use FormData in node.js without Browser?
6 Answers 6 · 2. Thanks for your answer. · If its node js, you only can do var FormData = require('form-data'); Node...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

Node 18 was just released and it comes with a native
FormDataand that also should be supported. This is what I get with axios 0.27.2I was going to add support for it (both
form-dataandformdata-node) when I did a PR with the FormData enhancement for Axios about six months ago, but then I decided to keep onlyform-datafor a while, since the package was pretty new. Most likely in the near future we should replace the default form-data module with formdata-node, or create our own simple stream encoder, but writing it in ES5 is painful.Currently, you can use a custom transform to support this package (both
form-data&formdata-nodesimultaneously)