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
Have you ever encountered this problem ?