【问题标题】:Follow redirect on loadImage() function跟随 loadImage() 函数的重定向
【发布时间】:2019-06-19 08:14:13
【问题描述】:

我在尝试使用 loadImage() 函数时总是收到错误“错误:服务器响应 301”

我在函数中提供的 URL 从 http 重定向到 https,但函数没有遵循重定向,而是返回了该错误。

async run(msg, { item }) {
    const canvas = Canvas.createCanvas(330, item.height);
    const ctx = canvas.getContext('2d');
    ctx.fillStyle = 'rgb(54, 57,62)';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    const iconImg = await Canvas.loadImage(item.icon); // <---
    ctx.drawImage(iconImg, 0, 0);
    const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'image.png');
    msg.channel.send(attachment);
}

有什么方法可以使该函数遵循 301 重定向的重定向而不是返回该错误?

【问题讨论】:

    标签: javascript node.js canvas node-canvas


    【解决方案1】:

    这将在下一个版本 (https://github.com/Automattic/node-canvas/pull/1398) - 2.4.2 或 2.5.0 中修复。

    在此之前,您必须手动发出 HTTP 请求并遵循重定向。

    【讨论】:

      猜你喜欢
      • 2012-01-05
      • 2020-04-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多