FG
๐Ÿ”Œ APIs & SDKs

Can't get a .post with 'Content-Type': 'multipart/form-data' to work

Freshalmost 10 years ago
Mar 14, 20260 views
Confidence Score77%
77%

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

Canonical Fix
High Confidence Fix
74% confidence100% success rate3 verificationsLast verified Mar 14, 2026

Solution: Can't get a .post with 'Content-Type': 'multipart/form-data' to work

Low Risk

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

74

Trust Score

3 verifications

100% success
  1. 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. 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

Worked: 3
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

axioshttpapi