Image Gen Issue

Hi,

I am currently developing an Image Gen API which uses Canvas and Express.JS. The project and endpoint loads fine and I seemed to have an issue with trying to query and pass the image link/text to generate the image.

Example Link: https://natebot-apibeta.glitch.me/image/approved?url=https://i.imgur.com/7xTdTUK.png
It returns:
55%20pm

app.get('/image/approved', async (req, res) => {
  if (!req.body.url) return status(false, 'No URL Provided', res);
  let check = await isImage(req.body.url);
  if (!check) return status(false, 'Invalid Image Type.', res);
  let result = await ApprovedEndpoint(req.body.url);

  return status(result[0], result[1], res);
});

Same thing happens to text endpoint. if I change the “url=” to “text=” it will show “No Text Provided”. Perhaps I am using the wrong usage of the API link? Code seems very fine to me.

Project: natebot-apibeta

Thank you

1 Like

Hey @NTMNathan,

I couldn’t find the project natebot-apibeta! Perhaps it is set to private?

I’ll send you an invite link to your DM

Just for clarification, I am using the following module versions:

  • “body-parser”: “^1.18.3”,
  • “canvas”: “^2.3.1”
  • “express”: “^4.16.4”
  • “node-superfetch”: “^0.1.9”
  • “request”: “^2.88.0”

Using req.query instead of req.body should fix your issue!

req.body is for POST requests.

Doesn’t really resolve the issue unfortunately. It’ll return this if I change from req.body to req.query

Result:
https://natebot-apibeta.glitch.me/image/approved?url=https://cdn.discordapp.com/avatars/520531771679571970/c3f97ccda0ec9c5b93336efa6e46ec10.png?size=2048

The link you sent works fine. It could be the way your sending back the data. To add: your response returns a Buffer object which you can use Buffer.toString(“whatevercencoding”) to concert the buffer to a string.

Hmm, yes. I can try that. But heres an example of what that link should have returned:

This is another API:
First Example
https://api.alexflipnote.dev/filter/blur?image=https://cdn.discordapp.com/avatars/417811612133490691/1059248469d4580bfe2b413603822f63.png?size=2048

Second Example
https://nekobot.xyz/api/imagegen?type=captcha&url=https://cdn.discordapp.com/avatars/520531771679571970/db4142c4f7311c0abe3424e886c5a35f.png?size=2048&username=NTM%20Nathan

Instead the response on my API just returns a series of numbers…
If you like an invite to the project to investigate, i’ll send you one in private message

I currently have to go somewhere now but when I get back I can take a look!

1 Like

I’ve found your issue. You seem to be returning a Buffer object.

However, I have modified the code to return a ReadableStream which can be written to the response which then shows the PNG/image.

2 Likes

Awesome, thank you for resolving the issue.

1 Like