Eu estou trabalhando na minha própria api, utilizando Express e o Nó j e estou a fazer algo que retorna engraçado gato imagens. Aqui é onde eu estou com a aleatórios engraçado gato imagens.
app.get("/media/bigfootjinx", (req, res, next) => {
let file = Math.floor(Math.random()*catarray.length)
let fileurl = catarray[file]
let fileimg = fetch(fileurl)
let img = Buffer.from(fileimg, 'base64');
res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length
});
res.end(img);
});
Meu objetivo é ter uma aleatórios gato imagem de volta, eles estão todos em png e links para uma discórdia cdn. O erro im constantemente recebendo é isso.
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Promise
at Function.from (buffer.js:330:9)
at /home/runner/api/index.js:21:22
at Layer.handle [as handle_request] (/home/runner/api/node_modules/express/lib/router/layer.js:95:5)
at next (/home/runner/api/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/runner/api/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/runner/api/node_modules/express/lib/router/layer.js:95:5)
at /home/runner/api/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/runner/api/node_modules/express/lib/router/index.js:335:12)
at next (/home/runner/api/node_modules/express/lib/router/index.js:275:10)
at expressInit (/home/runner/api/node_modules/express/lib/middleware/init.js:40:5)
Eu estou usando um replit node.js o projeto, se alguém ficou curioso.