How can I avoid UnicodeDecodeError when trying to upload binary files to a local SAM lambda with API Gateway?

0

Hello

I'm trying to run a SAM instance locally containing an API Gateway and a Lambda written in python. My goal is to POST images to my API so that I can upload them to an S3 bucket where they can be publicly served.

If I do HTTP operations using JSON everything works fine, but when I try to POST a binary type like 'image/jpeg' I get the following error:

2023-03-18 09:06:27  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
UnicodeDecodeError while processing HTTP request: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
2023-03-18 09:06:34 127.0.0.1 - - [18/Mar/2023 09:06:34] "POST /media HTTP/1.1" 502 -

I've tried adding BinaryMediaTypes to my template.yaml and create a fully defined CloudFormation but I still get this error.

Here's my code: https://github.com/caelumvox/blog-api-snip

Would anyone know how to get this working locally? Thank you

Nessuna risposta

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande