Estoy trabajando en mi propia api, utilizando Express y el Nodo JS y estoy haciendo algo que devuelve divertido gato de imágenes. Heres donde estoy con el azar divertido gato de imágenes.
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);
});
Mi objetivo es conseguir un azar gato de la imagen de la espalda, todos ellos están en png y enlaces a una discordia cdn. El error de im recibiendo constantemente es este.
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)
Estoy usando un replit node.js proyecto, por si alguien tenía curiosidad.