Cannot upload file within FormData
See original GitHub issueDescribe the bug
After upgrading from 0.24.0 to 0.25.0 File Form upload breaks.
To Reproduce
Original working on 0.24.0 code.
axios({
method: "post",
url: [serverUrl],
data: formData, // FormData object instance with uploading file field
timeout: 120000
});
This code was working previously, but now backend cannot extract file field. After specifying content type:
axios({
method: "post",
url: [serverUrl],
data: formData, // FormData object instance with uploading file field
timeout: 120000,
headers: {"Content-Type": "multipart/form-data"},
});
I got an error on backend “bad content-type header, no multipart boundary”
Expected behavior
Seems like previous version of axios (0.24.0) automatically add correct header and also boundary. Or was there any breaking change that I didn’t notice?
Environment
- Axios Version [0.25.0]
- Node.js Version [16.0.0]
- Additional Library Versions [formidable 2.0.1, React-Native 0.66.4]
Additional context/Screenshots
Not needed.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:20
- Comments:27 (3 by maintainers)
Top Results From Across the Web
Problem with uploading file through form-data axios
here my code to upload file in node.js, it works ok. const form = new FormData(); const file = fse.createReadStream(option.
Read more >I cannot upload file via HTTP Action with form-data type.
The API from other services can only upload files with form-data type. I try to use form-data type on HTTP action but it...
Read more >Send a File With Axios in Node.js - Maxim Orlov
Construct a form with form-data library. Before uploading a file with axios, you first need to create a form and append the file...
Read more >Using FormData Objects - Web APIs | MDN
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending...
Read more >Question: How to upload a file using HTTP POST Form-Data?
I want to upload a file using HTTP POST where username and password are to be filled using form-data. It works well from...
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
Seems like there is a problem in isFormData function:
I am using axios in react-native project where:
Why are these kind of useless “optimizations” even done? Why change something that works? Nobody will see any speed improvement.