axios: Can not change Contant-Type when data is FormData
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
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 9
- Comments: 17 (4 by maintainers)
One really ugly hack, without rewriting the app would be to hack object’s prototype. This will make
Content-typestay as it is.https://github.com/axios/axios/blob/283d7b306ce231f092d28e01713905e5c1600d14/lib/adapters/xhr.js#L16 This is probably the cause.
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
@ppozniak Unfortunately, I can’t change the behavior of axios. Finally I solved the problem by using XMLHttpRequest.