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: open
- Created 6 years ago
- Reactions: 9
- Comments: 16 (3 by maintainers)
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
One really ugly hack, without rewriting the app would be to hack object’s prototype. This will make
Content-type
stay as it is.@ppozniak Unfortunately, I can’t change the behavior of axios. Finally I solved the problem by using XMLHttpRequest.