-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Description
Is 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
nodeconst 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: { [...]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels