【问题标题】:Nodejs upload file to S3Nodejs上传文件到S3
【发布时间】:2021-11-28 12:08:26
【问题描述】:

我正在使用无服务器框架和 AWS Lambda 将文件/图像上传到 S3。数据来自 multipart/form-data 表单,因此我以二进制格式获取文件。

Example of POST request from REST client (Insomnia)

上传到 S3 代码:

this.client
    .putObject({
        Bucket: s3bucket,
        Key: s3path,
        Body: Buffer.from(data, 'binary'),
        ContentType: params.mimetype
    })
    .promise();

问题是上传到 S3 的文件或图像已损坏:

图片“http://xxxxx.eu-west-3.amazonaws.com/xxx 无法显示,因为它包含错误。

我已经在我的无服务器文件配置中为 api gateway 设置了 binaryMediaTypes :

apiGateway: {
  binaryMediaTypes: ['*/*'],
},

和 AWS API Gateway Binary Media Types config 一样,我设置 * / * 时 * / * 表示所有媒体类型

API Gateway Config

你遇到过这个问题吗?

【问题讨论】:

    标签: javascript node.js amazon-s3 aws-lambda serverless-framework


    【解决方案1】:
    1. 在集成请求中检查content handling: passthrough
    2. 接受HTTP Headers 部分中的传入请求标头。 Refer this

    Related issue

    【讨论】:

      猜你喜欢
      • 2019-12-13
      • 2020-01-29
      • 2015-03-17
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 2020-07-26
      相关资源
      最近更新 更多