1

I'm using Serverless Framework with AWS Lambda to upload files/images to S3. The data come from a multipart/form-data form so I get file(s) in binary format.

Example of POST request from REST client (Insomnia)

Upload to S3 code :

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

The problem is files or images uploaded to S3 are corrupted :

The image "http://xxxxx.eu-west-3.amazonaws.com/xxx cannot be displayed because it contains errors.

I already set binaryMediaTypes in my Serverless file config for api gateway :

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

and the same in AWS API Gateway Binary Media Types config, I set * / * when * / * means all media types

API Gateway Config

Have you ever encountered this problem ?

1 Answers1

0
  1. In the integration request check if the content handling: passthrough
  2. Accept the incoming request headers in HTTP Headers section. Refer this

Related issue

Ruben
  • 558
  • 3
  • 15