Can't get a .post with 'Content-Type': 'multipart/form-data' to work
See original GitHub issueI’ve spent a few hours today trying to get a post request to work with a few parameters and a file that I need to upload.
I was able to make it work with pure javascript and XMLHttpRequest but it doesn’t work with Axios. What am I doing wrong?
Here’s the code that works using XMLHttpRequest:
let data = new FormData();
data.append('action', 'ADD');
data.append('param', 0);
data.append('secondParam', 0);
data.append('file', new Blob([payload], { type: 'text/csv' }));
// this works
let request = new XMLHttpRequest();
request.open('POST', url);
request.send(data);
What would be the ‘Axios’ version of that?
Here’s one of my tries (the simple one):
// this won't work
const config = { headers: { 'Content-Type': 'multipart/form-data' } };
axios.post(url, data, config)
.then(response => console.log(response))
.catch(errors => console.log(errors));
Thank you! And thanks for your great work with Axios!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:144
- Comments:99 (9 by maintainers)
Top Results From Across the Web
'multipart/form-data' to work Axios React Native - Stack Overflow
Using the latest version of Axios, you make an HTTP request with 'Content-Type': 'multipart/form-data' in the header as follows:
Read more >Having trouble sending an HTTP POST request with form-data ...
If I do specify Content-Type = "multipart/form-data", I get a 400 Bad Request error and no response/error message.
Read more >How to post form with header multipart/form-data with HTTP ...
I need to post data to a service in form format (content-type as multipart/form-data). As per official document guided- we may set payload...
Read more >Question: How to upload a file using HTTP POST Form-Data?
You'll need to use the HTTP content type "multipart/form-data" to do this, which Boomi doesn't have pre-defined. You'll need to type it into...
Read more >[Multipart/form-data] Getting a wrong media file typer error on ...
Set the request content-type to "application/octet-stream" and check whether same content-type is allowed in webserver (supported) mime-types. 0. 1. 16 Jun 2021.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
@rafaelbiten I’ve just tried to reproduce the issue but to no avail. I used the following code:
The data was successfully sent to the server:
Two years latter: Same problem…