-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
formdata gets stringified #447
Comments
This only happens on client side btw |
I was playing around with this issue, and right now I patched it like this: I acutally "inverted" the check, now I only stringify objects to json if they are plain javascripts objects, and let the others as they are: export function isPlainObject(obj) {
const prototype = Object.getPrototypeOf(obj);
return (
prototype === null ||
prototype.constructor === Object ||
prototype.constructor === null ||
prototype.toString() === '[object Object]'
);
} this is even supported by ie11. |
I think this is also causing problems for me when trying to post form binary data to the Apigee API to deploy proxies (zip files), makes sense that it doesn't work if all form data is stringified.. Here's my code (using google-auth-library-nodejs, which uses gaxios): const form = new FormData();
var newFile = fs.readFileSync(bundlePath);
form.append('file', newFile, `${proxyName + ".zip"}`);
client.request({
url: `https://apigee.googleapis.com/v1/organizations/${projectId}/apis?name=${proxyName}&action=import`,
method: "post",
headers: {
...form.getHeaders()
},
data: form
}) And the error: Works fine with axios, so switched back to that for now. |
Hi @simllll, I have a PR open to fix this issue. One thing I'm not sure about is that you mention that data is stringified because of this line, but that actually stringifies the body. Did you mean to say that the body gets stringified, which you want fixed? Just to confirm, I've added an assertion here that confirms we do nothing to the body, which is what I'm assuming you're looking for. LMK if that looks right to you. |
I'm going to merge since this issue has gone OOSLO. Feel free to reopen if we need to make any other changes. |
Environment details
gaxios
version: 4.3.2Steps to reproduce
send a form dat areuqest
The request is stringiefied because of this line here
gaxios/src/gaxios.ts
Line 247 in cc3dd89
formdata is typeof object.
a possible fix will be to check if object is a formdata first and in this case don't touch it?
e.g.
altenative would be to allow skipping the whole transformation step in the validate step.. e.g. via flag?
The text was updated successfully, but these errors were encountered: