Skip to content

fix: remove forced multipart/form-data placeholder header in postForm/putForm/patchForm - #10980

Closed
ErnestHysa wants to merge 1 commit into
axios:v1.xfrom
ErnestHysa:fix/10886-multipart-placeholder-header
Closed

fix: remove forced multipart/form-data placeholder header in postForm/putForm/patchForm#10980
ErnestHysa wants to merge 1 commit into
axios:v1.xfrom
ErnestHysa:fix/10886-multipart-placeholder-header

Conversation

@ErnestHysa

@ErnestHysa ErnestHysa commented May 31, 2026

Copy link
Copy Markdown

Fixes axios/axios #10886.

Removes the forced bare Content-Type: multipart/form-data placeholder header in postForm/putForm/patchForm helper methods. The adapter now correctly sets the Content-Type with the proper boundary.


Summary by cubic

Removes the forced multipart/form-data placeholder header from form helpers so the adapter sets the correct Content-Type with boundary. Fixes #10886 and ensures proper multipart uploads.

Description

  • Summary of changes
    • Stop setting a bare Content-Type: multipart/form-data in postForm/putForm/patchForm.
    • Leave headers empty so the adapter can add multipart/form-data; boundary=....
  • Reasoning
    • The placeholder header blocked the adapter from adding the required boundary.
  • Additional context
    • Applies to all adapters/environments; behavior only changes for requests using FormData helpers.

Docs

  • Update /docs/ to clarify:
    • Do not set Content-Type manually for FormData; axios sets it with the correct boundary.
    • Examples for postForm/putForm/patchForm should omit manual headers.

Testing

  • No tests added in this PR.
  • Recommended:
    • Add tests ensuring the request headers include multipart/form-data; boundary=... when using FormData with helpers.
    • Verify no bare multipart/form-data header is sent by default.
    • Confirm explicit user-provided Content-Type (if set) is respected.

Semantic version impact

  • Patch: bug fix with no API changes.

Written for commit 56edece. Summary will update on new commits.

Review in cubic

…r in postForm/putForm/patchForm

The placeholder Content-Type header prevented the adapter from setting the
proper Content-Type with boundary. The adapter now correctly handles it.
@ErnestHysa
ErnestHysa requested a review from jasonsaayman as a code owner May 31, 2026 15:36

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Ap-0007 Ap-0007 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this fix!

While removing the forced 'Content-Type': 'multipart/form-data' placeholder from postForm/putForm/patchForm solves the issue of sending bare headers in React Native Android, doing so unfortunately breaks auto-serialization for plain JavaScript object payloads.

The Problem

Axios's default request transformer in lib/defaults/index.js relies on detecting 'multipart/form-data' in the Content-Type header to trigger the serialization of plain objects to FormData:

if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
  // serializes plain object payload to FormData
  return toFormData(...);
}

If we completely remove the placeholder header, contentType will be empty, and the plain object will fall through to standard JSON serialization (producing Content-Type: application/json).

Suggested Solution

The root cause for React Native Android is that resolveConfig.js only clears the Content-Type header if platform.hasStandardBrowserEnv is true. Since React Native excludes standard browser environment flags but uses standard FormData without getHeaders(), the placeholder is never cleared.

Instead of removing the placeholder header from the helpers, we can update lib/helpers/resolveConfig.js to clear the Content-Type header for any standard FormData object (i.e. those without .getHeaders()):

  if (utils.isFormData(data)) {
    if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv || !utils.isFunction(data.getHeaders)) {
      headers.setContentType(undefined); // Let browser/RN runtime handle it and append the boundary
    } else if (utils.isFunction(data.getHeaders)) {
      // Node.js FormData (like form-data package)
      // ...

This ensures:

  1. postForm auto-serialization continues to work by keeping the placeholder header during request transformation.
  2. The placeholder header is correctly stripped before the adapter runs in standard environments and React Native, allowing the runtime to generate the proper boundary.

@jasonsaayman jasonsaayman added the commit::fix The PR is related to a bugfix label Jun 17, 2026
@jasonsaayman jasonsaayman changed the title fix(#10886): remove forced multipart/form-data placeholder header in postForm/putForm/patchForm fix: remove forced multipart/form-data placeholder header in postForm/putForm/patchForm Jun 17, 2026
@jasonsaayman

Copy link
Copy Markdown
Member

The PR is superseded by the already-merged React Native FormData fix in #10898, and this diff introduces a public behaviour regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop forced bare multipart/form-data placeholder header in postForm/putForm/patchForm (breaks RN Android)

3 participants