简体   繁体   English

使用 API 网关从 S3 下载已压缩的文件

[英]Using API Gateway to download already gzipped files from S3

I have an API frontend to a few things, one of those is an S3 bucket containing lots of files.我有一个 API 前端来处理一些事情,其中之一是一个包含大量文件的 S3 存储桶。

When I setup a resource that integrates with my S3 bucket, this works perfectly fine for standard text data, but fails for files that are already gzipped.当我设置一个与我的 S3 存储桶集成的资源时,这对于标准文本数据非常有效,但对于已经 gzip 压缩的文件则失败。

How do I tell API Gateway to just pass through the gzipped file as a binary stream?我如何告诉 API 网关将 gzip 压缩文件作为二进制 stream 传递?

I need to use API Gateway for authentication, so I can't just get around it by using the s3 bucket to serve my files.我需要使用 API 网关进行身份验证,所以我不能通过使用 s3 存储桶来提供我的文件来解决它。

I also need gzip encoding turned on for nearly every other endpoint, so turning that off will cause other problems to already working endpoints.我还需要为几乎所有其他端点打开 gzip 编码,因此关闭它会导致已经工作的端点出现其他问题。

The "other" working content - are there only text files or as well binary content files? “其他”工作内容 - 只有文本文件还是二进制内容文件?

You have to set some parameter when handling binary content with the default (not http-only) API Gaeway.使用默认(非 http-only)API Gaeway 处理二进制内容时,您必须设置一些参数。 See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html (this is only my assumption about the problem as you still failed to provide any repeatable and validable example, how the API Gateways is providing the content? As Lambda? Code? )请参阅https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html (这只是我对问题的假设,因为您仍然未能提供任何可重复和有效的示例,如何API 网关提供内容?作为 Lambda?代码?)

As well there's 10MB limit for API Gateway payload. API 网关有效负载也有 10MB 的限制。 If you want to return longer content (actually - I'd use it for all content), the API Gateway can return a pre-signed URL for S3 (or web distribution) so the client could download the content of any length from the S3 bucket (directly or through the CloudFront).如果您想返回更长的内容(实际上 - 我会将其用于所有内容),API 网关可以为 S3 返回一个预签名的 URL(或 Z2567A5EC9705EB7AC2C2C984033E061 的任何长度的内容)存储桶(直接或通过 CloudFront)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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