Skip to content

Axios fetch adapter: Missing boundary when Content-Type is set manually with FormData #7054

@ayush-0513

Description

@ayush-0513

Describe the bug

When using the fetch adapter with FormData, if I manually set the Content-Type: multipart/form-data header, Axios does not include the boundary, which causes the server to reject the request.

This is inconsistent with native fetch, which automatically appends the boundary even if the header is set manually.

To Reproduce

`import axios from "axios";

const http = axios.create({ adapter: "fetch" });

const form = new FormData();
form.append("file", new Blob(["test content"], { type: "text/plain" }), "test.txt");

// Manually set Content-Type
const { data } = await http.post("/upload", form, {
headers: { "Content-Type": "multipart/form-data" },
});
`

Code snippet

Content-Type: multipart/form-data   <-- missing boundary

Expected behavior

Axios should either:

  • Automatically append the correct boundary to multipart/form-data, or
  • Warn developers not to override Content-Type when using FormData.

Axios Version

1.12.0

Adapter Version

fetch

Browser

Chrome 139.0.7258.67

Browser Version

No response

Node.js Version

22.17.1

OS

Windows 11

Additional Library Versions

React 19.1.1, Next.js 15.4.6, Hono 4.9.0

Additional context/Screenshots

This can cause confusion because the default Axios adapter and native fetch both handle this correctly. It would help if Axios either normalized this behavior or documented it clearly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue::bugThis issue is related to a bug that requires fixing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions