Skip to content

Content type changed from multipart/form-data to application/x-www-form-urlencoded #5067

Closed

Description

@Flamenco

My content-type header of multipart/form-data is getting replaced with another content-type. This was not an issue until I switched to v1.0.x

const api = axios.create({
 headers: {
  'Content-Type': 'application/json'
 }
})

const formData = new FormData()
formData.append('file', file)
api.post('endpoint', formData, {
  headers: {
   'Content-Type': 'multipart/form-data'
 }
})

However, this works:

axios({
 url: 'endpoint',
 method: 'post',
 data: formData,
 headers: {
   'Content-Type': 'multipart/form-data'
 }
})

This was sent with the old version, and the workaround mentioned:
Screen Shot 2022-10-08 at 4 46 55 PM

And this started happening when I upgraded.

Screen Shot 2022-10-08 at 4 46 40 PM

Activity

  1. changed the title [-]Content type changed from multipart/form-data to application/x-www-form-ulrencoded[/-] [+]Content type changed from multipart/form-data to application/x-www-form-urlencoded[/+] on Oct 8, 2022
  2. GamalC commented on Oct 10, 2022

    @GamalC

    I believe that I had to adjust to some changes made in headers processing as well. Adding here in case it helps someone.

    I am sending an Axios POST request with the following data:
    var data = {'key1': value1, 'key2': value2 };

    And had Headers:
    var default_headers = { ... 'Content-type': 'application/x-www-form-urlencoded', ...};

    In version 0.22.0, the decoded content was:
    {"key1":"value1","key2":"value2"}

    In version 1.0.0+ it is now:
    key1=value1&key2=value2

    The update now seems to be the correct processing if Content-Type is set to 'application/json' (which now seems to work in 1.0.0+) but it initially caused a crash after updating when I tried to load the JSON.

  3. physicsSorcererKing commented on Oct 14, 2022

    @physicsSorcererKing

    @Flamenco Don't add 'Content-Type': 'multipart/form-data' by yourself before this issue is solved.
    axios will automatically do this if config.data's type is FormData
    see https://github.com/axios/axios/tree/main#formdata

  4. DigitalBrainJS commented on Oct 14, 2022

    @DigitalBrainJS
    Collaborator

    Can you reproduce the issue here?

  5. Flamenco commented on Oct 14, 2022

    @Flamenco
    Author

    @physicsSorcererKing I am adding it because my base axios, that had all sorts of headers and logic, declared content type of "application/json", as shown. I need to override it. Perhaps overriding it as 'undefined' might work.

  6. physicsSorcererKing commented on Oct 14, 2022

    @physicsSorcererKing

    @DigitalBrainJS I found I spelled lowercase content-type caused it happened.
    Not sure is this @Flamenco 's case.

  7. DigitalBrainJS commented on Oct 14, 2022

    @DigitalBrainJS
    Collaborator

    OK. I found the problem, so I will fix it soon.

  8. jasonsaayman commented on Nov 10, 2022

    @jasonsaayman
    Member

    Hi 👋

    Please try the latest pre-release by running the following:

    Please provide feedback in either the pinned issue or discussion thread 🧵

  9. FelipeEduardoR2 commented on Nov 16, 2022

    @FelipeEduardoR2

    @jasonsaayman
    Eu testei e no meu caso resolveu!
    (I tested and it's ok!)

  10. darkvertex commented on Nov 18, 2022

    @darkvertex

    I also had an issue where my headers were getting ignored during a multipart formdata call and Axios was submitting it as a urlencoded form data, which my backend did not likey.

    [email protected] fixed this behaviour for me and my multipart calls work again. 🎉

  11. Soneji commented on Nov 26, 2022

    @Soneji

    Same issue, axios 1.2.0 is out now and fixes this!

  12. rohit9625 commented on Jul 16, 2025

    @rohit9625

    Well, I can see the same issue for 1.10.0 version. I can see that the latest version is still 1.10.0. Is anyone?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions