我的工作我自己的api,使用表达和节点JS和我做的东西回猫的图像。 这是我在哪的随机搞笑的猫的图像。
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);
});
我的目标是获得一个随机的猫的图像回,他们都是在png并链接到一个不和谐cdn。 错误im不断越来越是这样的。
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)
我使用一个replit node.js 的项目,如果任何人都很好奇.