I've a Lambda function written in Go that supposed to allow image file upload—via an HTML form/JavaScript and an API Gateway integration—into an S3 bucket, all defined in a SAM template.
Here's an example of the Lambda function execution log:
Now the problem is that for any JPEG or PNG files I get corrupted results:
- The file size of the resulting image (what I get once I parse the
multipart
media message) is larger than the original file size, for example: 8kB (original) to 12kB (S3 bucket). - When I compare the original PNG or JPEG files with the resulting ones in the S3 bucket with
hexdump
they almost look identical(that is to say: I doubt there's a base64 encoding issue involved). - Interestingly, for the
text/plain
media type this setup works.
I've tried to figure out where things break and at the current point in time my hunch is that there's something in the API Gateway configuration I am missing. FWIW, I tried this but no observable change in behavior:
$ aws apigateway update-integration-response \
--rest-api-id XXX --resource-id XXX \
--http-method POST --status-code 200 \
--patch-operations op='replace',path='/contentHandling',value='CONVERT_TO_BINARY'`