question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not change Contant-Type when data is FormData

See original GitHub issue
axios({
                method: "PUT",
                url: url,
                transformRequest: [function (data, headers) {
                    // Do whatever you want to transform the data
                    return formData;
                }],
                headers: {
                    'Content-Type': file.type
                },
                "withCredentials": false
            });

Launched request with Content-Type: Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryPz13ZA77aLqgPlwB

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
norbertsongincommented, May 7, 2021

It’s because of this part https://github.com/axios/axios/blob/master/lib/adapters/xhr.js#L18-L20 Looks like it was first reported in 2017 https://github.com/axios/axios/issues/767 but was closed without being fixed

Removing this part worked for me

2reactions
ppozniakcommented, Apr 3, 2019

One really ugly hack, without rewriting the app would be to hack object’s prototype. This will make Content-type stay as it is.

transformRequest: payload => {
       // ...
        Object.setPrototypeOf(formData, null);
        return formData;
      },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to send formData to the server - Stack Overflow
I am using Angular framework ,; Where I am trying to send data to the server via FormData; I ...
Read more >
[Solved]-Facing problem in sending form data on the server-angular.js
You can not directly print FormData to console.log(), You need to use methods of ... change contant type from headers = headers.append('Content-Type', ...
Read more >
Orckestra/C1-CMS - Gitter
Hi. I've recently added two new fields to an in-use page datatype on my home machine and everything works as it should. However,...
Read more >
axios - Bountysource
Trying to send a request (no matter what) the timeout will be ignored and is ... Getting network error when sending form data...
Read more >
3.1.0-beta2 | Silverstripe CMS Documentation
This version of Silverstripe CMS will not recieve any additional bug fixes or ... Changed action handling and allowed_actions to make more secure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found