【问题标题】:AWS API Gateway Binary CorruptionAWS API Gateway 二进制损坏
【发布时间】:2019-06-19 10:01:35
【问题描述】:

我有一个问题,我的 API Gateway + Lambda 集成正在通过 API Gateway 进行某种形式的内容映射。

我的 API 网关带有一个使用 Lambda 代理集成的端点。

我已启用二进制媒体类型: 图片/JPEG 图片/png 图片/webp 图片/* /

端点获取图像,根据您使用的浏览器将其优化为 jpeg 或 webp。

对于 Firefox,它会按预期返回图像/jpeg。

在 Chrome 中查看(返回 webp 文件)会导致返回一个方框。 (这一切都适用于 Elastic Beanstalk,所以我知道这是一个网关问题)

在 Chrome 中,我可以看到某种映射正在发生:

content-length: 4710
content-type: image/webp
status: 200
x-amz-apigw-id: UEG2ZE8vDoEFR8A=
x-amzn-remapped-content-length: 2580
x-amzn-requestid: 6217195f-20ae-11e9-9faf-ebf6a6f5765d
x-amzn-trace-id: Root=1-5c4b1e8f-cab2e4fd2564412ef5914509;Sampled=0

值:x-amzn-remapped-content-length 是应该返回的长度。我不确定是什么过程扭曲了数据的返回。

代理集成设置

API 网关配置

【问题讨论】:

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


    【解决方案1】:

    对于其他陷入此问题的人,我需要在我的 Lambda 入口点中注册二进制类型,见下文:

    public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
    {
        protected override void Init(IWebHostBuilder builder)
        {
            // Register any MIME content types you want treated as binary
            RegisterResponseContentEncodingForContentType("image/jpeg", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/webp", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/png", ResponseContentEncoding.Base64);
    
            builder
                .UseStartup<Startup>();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 2021-07-29
      • 2017-04-23
      • 2021-02-08
      相关资源
      最近更新 更多