Not work with FormData
MeloJR opened this issue · 5 comments
When you pass FormData
objects as the data parameter the library sends the request as application/json
.
The problem is here:
if (data && typeof data === 'object') {
data = JSON.stringify(data);
customHeaders['Content-Type'] = 'application/json';
}
as typeof new FormData() === 'object'
.
Good catch. Happy to accept a PR, this will likely require inspecting the constructor.
Hi!
would the solution to this be, check if data is FormData and set a different Content-Type? If it's that I can fix it and send a PR
@crissto I guess we can just check !(data instanceof FormData)
But not sure if that has side-effects... hope @developit knows more than me about it :D
@fabricionaweb yup, that's likely going to be the smallest check.
Another option would be checking if (typeof data.append=='function'){}
, but the size win likely isn't worth the false positive chance.
Fix published in version 0.3.0.