Can't post FormData since Axios 0.25.0
See original GitHub issueDescribe the issue
I can’t post FormData since "axios": "^0.25.0",
Error: Request failed with status code 400
Example Code
export const client = axios.create({
baseURL: URL_API,
withCredentials: true,
responseType: 'json',
timeout: 30000,
});
const params = new FormData();
params.append('name', data.model);
params.append('idFuel', data.idFuel);
params.append('power', data.idPower);
client.post(`/app/society/${idSociety}/vehicle`, params, { headers: { "Content-Type": "multipart/form-data" } })
Expected behavior, if applicable
That it works
Environment
- Axios Version: 0.25.0
- Node.js Version: v14.17.6
- OS: iOS 15, Android 11 (But on all platforms and versions)
- Additional Library Versions: React Native 0.64.3
Additional context/Screenshots
No problem with "axios": "^0.24.0",
I saw this PR https://github.com/axios/axios/pull/3757 on 0.25.0, but I don’t know what I have to change in code.
Thanks for your help 👍
Issue Analytics
- State:
- Created 2 years ago
- Reactions:34
- Comments:46 (4 by maintainers)
Top Results From Across the Web
Why does 'formData' not work in 'axios 0.26.1' in react native ...
This bug has been posted on Axios GitHub issues and apparently it is present since 0.25.0. I had to roll back to version...
Read more >axios - npm
Promise based HTTP client for the browser and node.js. Latest version: 1.2.1, last published: 23 days ago. Start using axios in your project ......
Read more >axios/CHANGELOG.md - UNPKG
There is a bug in react native Android platform when using get method. It will trigger a 'Network Error' when passing the requestData...
Read more >POST form data using Axios API in JavaScript (including a file)
Source code: https://openjavascript.info/2022/08/03/ post - form-data -using- axios /⚡ Looking for high-performance, affordable web hosting for ...
Read more >cannot read properties of undefined (reading 'data') axios
I need to post some form data to a mockapi endpoint, using Axios and Vuex. I'm using Vue Cli v2, and Vuex 3....
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 Free
Top Related Reddit Thread
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

It works for me:
Versions: react-native: 0.67.2 axios: 0.26.0
This is a shorter form, since it is still needed in 0.26.1
The headers value might only be needed if you have modified the default Content-Type for axios. (just a guess since I have read that axios should set the correct Content-Type based on the FormData type)
In which axios version will the fix that closed this issue be released?