AWS Lambda 损坏图像缓冲区 - 无服务器框架

问题描述 投票:0回答:0

我遇到一个问题,当我尝试将图像缓冲区发送到不和谐的 webhook 时,AWS lambda 破坏了我的图像缓冲区。它在本地与 SLS Offline 一起工作,我可以在 discord 通道中看到没有问题的图像,但是当我将它部署到 AWS 时,我得到了

而不是图像本身。环顾四周有这个问题的类似人我已经尝试添加到我的 serverless.yml

plugins:
   - serverless-apigw-binary

在自定义路径中带有

apigwBinary

apigwBinary:
    types: #list of mime-types
        - 'image/png'

我还看到了另一篇关于在 serverless.yml 中的 provider 下添加

AwsApiGateway
的帖子,就像这样

provider:
   AwsApiGateway:
   binaryMediaTypes:
      - 'image/png'

当我

console.log('Sending Buffer', buffer);
缓冲区以确保它确实存在于 cloudwatch 中时,我看到了

Sending Buffer <Buffer fd 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 04 fd 00 00 02.... 162236 more bytes>

所以缓冲区肯定是进入了 lambda,但是当它进入 discord 时它就被破坏了。但同样它在本地工作没有问题。所以 Lambda 正在以某种方式破坏它。

webhook.send({
        files: [{
            attachment: buffer,
            name: newFileName
        }]
    })
    .then((res) => {
        console.log('FINISHED', res);
    });
}
catch (e) {
    console.log('ERROR', e);
}

如何获取图像缓冲区以使其作为图像不和谐且不被损坏。感谢您的帮助!

node.js aws-lambda discord discord.js serverless-framework
© www.soinside.com 2019 - 2024. All rights reserved.