Repository navigation
Closed
Description
Describe the bug
When the request data value is an instance of the Node.js 18 FormData class the Axios throws the error with the next message.
Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream
Seems like the error goes from this part of the code:
Lines 236 to 251 in d032edd
| if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) { | |
| headers.set(data.getHeaders()); | |
| } else if (data && !utils.isStream(data)) { | |
| if (Buffer.isBuffer(data)) { | |
| // Nothing to do... | |
| } else if (utils.isArrayBuffer(data)) { | |
| data = Buffer.from(new Uint8Array(data)); | |
| } else if (utils.isString(data)) { | |
| data = Buffer.from(data, 'utf-8'); | |
| } else { | |
| return reject(new AxiosError( | |
| 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream', | |
| AxiosError.ERR_BAD_REQUEST, | |
| config | |
| )); | |
| } |
I suppose that current checks don't expect FormData object that goes not from either Browser or node-fetch package but from FormData type added to Node.js 18.
To Reproduce
const axios = require('axios');
(async () => {
const axiosInstance = axios.create({});
const FormData = global.FormData;
const data = new FormData();
data.append('somePropety', 'someValue');
try {
const response = await axiosInstance.request({
method: 'POST',
url: 'http://test.com',
headers: {
'Content-Type': 'multipart/form-data'
},
data,
});
console.log(response);
} catch (error) {
console.error(error);
}
})();Code snippet
No response
Expected behavior
Support of Node.js FormData added to Axios
Axios Version
1.2.0
Adapter Version
No response
Browser
No response
Browser Version
No response
Node.js Version
v18.12.1
OS
macOs 12.6.1
Additional Library Versions
No response
Additional context/Screenshots
No response
Metadata
Metadata
Assignees
Labels
No labels

Activity
gbersac commentedon Apr 14, 2023
I had this issue using
"axios": "^1.3.5"DigitalBrainJS commentedon Apr 14, 2023
@gbersac Could you share a minimal reproducible example in a fork of this sandbox?