FromData Axios and react native (web), inconsistent?
See original GitHub issueDescribe the issue
I’m trying to post a file using axios on react native (web):
Example Code
const form = new FormData()
form.append('image', image, 'image.jpg') // <-- Blob with mimetype 'image/jpeg'
axios.patch(`/image`, form, {headers:{"Content-type":"multipart/form-data"}})
Expected behavior, if applicable
When using react native web everything works fine, but when I’m using react native mobile the backend returns:
multipart file(s) required {"errors":[{"message":"multipart file(s) required","path":"/image"}],"name":"Bad Request","status":400}
What’s going on here? Why is the behavior different between web and mobile?
Environment
- Axios Version: ^0.25.0
- Browser: firefox
- React native version: 0.64.3
- React native web version: 0.17.1
Additional context/Screenshots
no additional content
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Problem using Axios FormData in React-Native - Stack Overflow
I'm working with a Recat-Native frontend and a Django backend. It al started with that I tried to set up a Axios Formdata...
Read more >User submits with inconsistent behaviour - Support
I am having some inconsistent behaviour when users submit data through my form. ... 'react-dropzone'; import axios from 'axios'; const addData = (object) ......
Read more >Network error on body exceeding a certain size-Reactjs
Coding example for the question Axios XMLHttpRequest - Network error on body exceeding a certain ... let formData = new FormData(); formData.append("files", ...
Read more >Killing CORS Preflight Requests on a React SPA
When I first saw them appearing in the web inspector, it confused me ... It is also unfortunate that preflight requests are incompatible...
Read more >ReferenceError: can't access lexical declaration 'X' before ...
The JavaScript exception "can't access lexical declaration `variable' before initialization" occurs when a lexical variable was accessed ...
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
No results found
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

Adding transformRequest will fix the issue, as mentioned here https://github.com/axios/axios/issues/4406#issuecomment-1048693170
FormData is broken since Axios 0.25. It is working perfectly fine with 0.24 on react-native. I wasted 4 hours until I’ve found a similar issue which told me to downgrade.
There are also StackOverflow issues. https://stackoverflow.com/questions/71321756/react-native-expo-axios-file-upload-not-working-because-axios-is-not-sending/71323380
And this issue (with a workaround): https://github.com/axios/axios/issues/4406
Version 0.24
Version 0.25 and Version 0.26