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

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠