简体   繁体   中英

How to receive file uploads behind aws api gateway?

I created a python flask api which accepts image uploading. Something similar to the following:

@app.route("/image_upload", methods=['POST'])
def image_upload():
  image = request.files['image']
  image_data = image.read()
  base64encoded = base64.b64encode(image_data).decode('utf-8')
  return base64encoded

I deployed it to okteto, and if I upload image against the okteto endpoint, it works well.

I then add an AWS API gateway to proxy the requests to the okteto endpoint:

在此处输入图像描述

I then try to upload the same image through the API gateway endpoint, then the image received in the flask will be corrupt.

I noticed that the payload seems twice as big as without the API gateway. And the base64 string can NOT be rendered as an image anymore.

So how does the API Gateway handle the file uploading? I tried searching in both google and AWS documents, there are many saying how to use API Gateway to upload files to S3. But I don't want to upload to S3. I just want the API Gateway forward the payload to my Flask app.

The image can be as small as needed. So it's far less than the limit of the gateway.

Fixed by adding the binary media types to the gateway.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM