0

我在推特图片的操作中遇到问题

错误:

Error: ENOENT: no such file or directory, open 'https://cdn.nekos.life/neko/neko088.jpg'
    at Object.openSync (fs.js:454:3)
    at Object.readFileSync (fs.js:354:35)
at twtRandomNeko (/app/bot.js:77:25)
    at processTicksAndRejections (internal/process/task_queues.js:88:5) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: 'https://cdn.nekos.life/neko/neko088.jpg'
}

这是代码:

async function twtRandomNeko() {
  const body = await superagent.get("https://nekos.life/api/neko");
  const img = body.neko;
  console.log(img); //example: https://cdn.nekos.life/neko/neko088.jpg
  try {
    var b64content = fs.readFileSync(img, { encoding: "base64" });
  } catch (e) {
    console.log(e);
  }

  twt.post("media/upload", { media_data: b64content }, function(
    err,
    data,
    response
  ) {
    console.log(data);
  });
}

setInterval(() => {
  twtRandomNeko();
}, config.intervals.neko);

我在google上搜索,没有找到解决方案,尝试了一些方法。我也想过做一个临时文件夹,但在继续之前,我决定提出这个问题,如果有人帮助我,我将非常感激:)

4

0 回答 0