-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Failed to parse body as FormData with Axios #3676
Comments
Can it be that Undici became strict to who constructs the FormData? The headers of the data clearly feature some Axiom boundary. Can that be the thing that upsets Undici? Does it only accept FormData instances created by itself? |
Could you provide an example that doesn't use axios or msw? I'd need the exact body (including \r\n's) and the content-type header to assess. |
@KhafraDev, that doesn't seem to be possible. I can omit MSW since it has nothing to do with this scenario, but the issue is specific to Axios. If you feel raising it with Axios is a better approach, I will do so. If nothing rings a bell by looking at the payload above, then I suppose the FormData payload is okay. I can share the request body as buffer, which should preserve the newlines and other characters. Would that help? |
I need the raw body and the content-type header. |
I found a repro without dependencies. Will have a fix soon. const response = new Response([
'--axios-1.7.7-boundary-bPgZ9x77LfApGVUN839vui4V7\r\n' +
'Content-Disposition: form-data; name="file"; filename="doc.txt"\r\n' +
'Content-Type: text/plain\r\n' +
'\r\n' +
'Helloworld\r\n' +
'--axios-1.7.7-boundary-bPgZ9x77LfApGVUN839vui4V7--\r\n' +
'\r\n',
].join(''), {
headers: {
'content-type': 'multipart/form-data; boundary=axios-1.7.7-boundary-bPgZ9x77LfApGVUN839vui4V7'
}
})
await response.formData() |
Thank you for fixing this, @KhafraDev! Amazing job, as always. |
Hi, in which version of node is this fixed ? @KhafraDev i am using node 23.3.0 and got the same issue |
This popped up again as of last week in Node 22 & 23. |
reopen this issue plz |
This popped up again as of last day in Node 20.13.0 ~ 23.6.0 OS: macOS 14.6.1 curl --location --request POST 'http://localhost:3000/api/icon/update' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: 10.98.108.52:3000' \
--header 'Connection: keep-alive' \
--header 'Content-Type: multipart/form-data; boundary=--------------------------827192901737642659031343' \
--form 'svg=@"/Users/mangosetsuna/Pictures/Icons/attachment.svg"' |
This issue has been closed for three months, please open a new issue if you consider the issue appeared once more. Do no forget to add an Minimum Reproducible Example |
Bug Description
When performing a POST request with FormData and Axios, Undici fails to parse the request body.
Reproducible By
This throws the following error:
I have a strong reason to believe something has changed in Undici between Node.js v21 and v22, which is causing this parsing issue. This same scenario is passing with the same dependencies using Node.js v18-v20.
Expected Behavior
Undici parses the FormData body sent from Axios.
Logs & Screenshots
Here's the FormData body read as text. This looks okay to me.
Environment
The text was updated successfully, but these errors were encountered: