Closed aymenitc closed 1 year ago
I downgraded node from 19.0.1 to 16.17.0 and it works 💯❤️
Does anybody know when it will be available for the 19+ NodeJS version? I did the whole project around it and it would be a nightmare to rewrite all of it just because of one lib. Version 16.17.0 - seems to work fine - but it's quite a big step back... Thanks in advance
@andreisuharew We'll be happy to fix this for you -- we are actually not JS experts sadly. Can you share some code and how to reproduce the problem and we'll fix it ASAP
I'm getting this error on newly installed Ubuntu vps. It is working fine on my old server The error:
Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream
My code:
const filename = `./media/colori.jpg` var resp = await deepai.callStandardApi("colorizer", { image: fs.createReadStream(filename), }) console.log(resp)
i have exactly the same code example just in try catch . I tested node 17 also works fine . In 18 and 19 versions i see error about invalid data - same as in title of this issue
@andreisuharew We'll be happy to fix this for you -- we are actually not JS experts sadly. Can you share some code and how to reproduce the problem and we'll fix it ASAP
You can simply try any of your example JS code on node 18+. Not sure why this is marked as closed since the issue is still very much present and downgrading node is not a solution but a workaround.
I don't want to downgrade node, but see this: https://stackoverflow.com/questions/56803702/axios-error-data-after-transformation-must-be-a-string-an-arraybuffer-a-buffer
Please revisit this issue deepai team @deepai-org, I would love to use one of your endpoints in my application without downgrading node.
The problem is related to how axios handles the FormData type, and some kind of change in that type in node 18. See https://github.com/axios/axios/issues/5327 where the question was raised and https://github.com/axios/axios/pull/5316 where it was resolved.
I think the fix should be as simple as updating your axios dependency.
I HAVE A WORKAROUND :) 🎉🎉 for anyone who comes across this thread
I copied some of the code in the DeepAI.js file (https://github.com/deepai-org/deepai-js-client/blob/master/lib/core/DeepAI.js) into my own route. I am using the super resolution endpoint and passing an image url, so I put the following in my route:
const axios = require('axios');
const FormData = require(form-data);
const imageUrl = 'some_image_url';
const axiosInstance = axios.create({
headers: {'client-library': 'deepai-js-client'},
});
axiosInstance.defaults.headers.common['api-key'] = process.env.DEEPAI_KEY;
const form = new FormData();
form.append('image', imageUrl);
const req_options = { withCredentials: true };
if (form.getHeaders !== undefined) {
req_options.headers = form.getHeaders();
}
const response = await axiosInstance.post(
'https://api.deepai.org/api/torch-srgan',
form,
req_options
);
console.log(response);
And then you can access the output url at response.data.output_url. Obviously it's a pretty straightforward workaround—it's just hitting the api directly where the library fails. But it works because this route is using axios version 1.4.0, which is updated to handle the new FormData in node versions 18 and later.
Of course the js client's axios dependency should still be updated. This workaround should be a temporary fix for those working in the new node versions.
I'm getting this error on newly installed Ubuntu vps. It is working fine on my old server The error:
Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream
My code: