Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Error: Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream #40

Closed
aymenitc opened this issue Nov 13, 2022 · 8 comments

Comments

@aymenitc
Copy link

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)
@aymenitc
Copy link
Author

I downgraded node from 19.0.1 to 16.17.0 and it works 💯❤️

@asukhariev
Copy link

asukhariev commented Nov 30, 2022

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

@deepai-org
Copy link
Owner

deepai-org commented Nov 30, 2022

@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

@asukhariev
Copy link

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

@Wheezle211
Copy link

@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.

@romw314
Copy link

romw314 commented Jun 5, 2023

@spejamas
Copy link

spejamas commented Jun 15, 2023

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 axios/axios#5327 where the question was raised and axios/axios#5316 where it was resolved.

I think the fix should be as simple as updating your axios dependency.

@spejamas
Copy link

spejamas commented Jun 16, 2023

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants