Can't get a .post with 'Content-Type': 'multipart/form-data' to work
Problem
I'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: [code block] What would be the 'Axios' version of that? Here's one of my tries (the simple one): [code block] Thank you! And thanks for your great work with Axios!
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Can't get a .post with 'Content-Type': 'multipart/form-data' to work
Possibly related header issue. When content-type is set in config object in request it is concatenated e.g. axios.post( 'https://example.com/login', {emailAddress: email, password: hashedPassword}, {headers: {'content-type': 'application/json'}} ); header content-type comes in as application/json,application/json body will not be parsed in thi
Trust Score
3 verifications
- 1
Possibly related header issue. When content-type is set in config object in req
axios.post( 'https://example.com/login', {emailAddress: email, password: hashedPassword}, {headers: {'content-type': 'application/json'}} );
- 2
header content-type comes in as application/json,application/json
body will not be parsed in this case
Validation
Resolved in axios/axios GitHub issue #318. Community reactions: 3 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep