已弃用 Jimp 中的 `Buffer` 破坏 AWS Lambda

问题描述

我正在编写一个图像大小调整 lambda 函数。它从 s3 读取一个对象并使用 jimp 来调整它的大小。当我运行它时,我收到此错误

ERROR   (node:9) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(),Buffer.allocUnsafe(),or Buffer.from() methods instead.

我已将其追溯到 jimp 中的 image.scaletoFit()。在本地运行时我没有收到此错误。两者都运行节点 14。我假设这是 AWS Lambda 特有的。

我的失败代码

    const { Body } = s3Result;  //body is a buffer
    const jimpImage = await Jimp.read(Body).then((image) => {
      
      // debug tells me the bug happens here
      let imageResult = image.scaletoFit(width,height)

      imageResult = imageResult.quality(
        quality
      );
      return imageResult.getBufferAsync("image/jpg");
    });

是否有解决此问题的方法,以便我可以继续使用 jimp

欢迎在评论中提供替代方案。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)