【问题标题】:How to receive file uploads behind aws api gateway?如何在aws api网关后面接收文件上传?
【发布时间】:2023-02-10 11:15:21
【问题描述】:

我创建了一个接受图像上传的 python flask api。类似于以下内容:

@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

我将它部署到 okteto,如果我针对 okteto 端点上传图像,它运行良好。

然后我添加一个 AWS API 网关来代理对 okteto 端点的请求:

然后我尝试通过 API 网关端点上传相同的图像,然后烧瓶中收到的图像将损坏。

我注意到负载似乎是没有 API 网关的两倍大。并且 base64 字符串不能再呈现为图像。

那么API网关是如何处理文件上传的呢?我尝试在google和AWS文档中搜索,有很多说如何使用API​​ Gateway将文件上传到S3。但我不想上传到 S3。我只希望 API 网关将有效负载转发到我的 Flask 应用程序。

图像可以根据需要尽可能小。所以远远小于网关的极限。

【问题讨论】:

  • 你上传的图片有多大?它可以大于 API 网关的最大负载大小吗?
  • 图像可以根据需要尽可能小。所以远远小于网关的极限。

标签: amazon-web-services aws-api-gateway


【解决方案1】:

通过将二进制媒体类型添加到网关来修复。

详细说明(虽然是中文):

【讨论】:

    猜你喜欢
    • 2019-05-27
    • 1970-01-01
    • 2013-08-29
    • 2019-01-21
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 2019-07-15
    相关资源
    最近更新 更多