我有一个AWS API Gateway充当后端服务的代理:
{
"apiKeySource": "HEADER",
"name": "-",
"createdDate": 1513820260,
"binaryMediaTypes": [
"application/zip",
"application/octet-stream"
],
"endpointConfiguration": {
"types": [
"EDGE"
]
},
"id": "-"
}
集成定义在这里:
{
"integrationResponses": {
"200": {
"responseTemplates": {
"application/json": null
},
"statusCode": "200"
}
},
"passthroughBehavior": "WHEN_NO_MATCH",
"timeoutInMillis": 29000,
"uri": "http://${stageVariables.backend}:7000/{proxy}",
"connectionType": "INTERNET",
"httpMethod": "ANY",
"cacheNamespace": "iv06s3",
"type": "HTTP_PROXY",
"requestParameters": {
"integration.request.path.proxy": "method.request.path.proxy",
"integration.request.header.X-Source-IP": "context.identity.sourceIp"
},
"cacheKeyParameters": [
"method.request.path.proxy"
]
}
我有一个端点,可以即时生成一个Zip文件并将其返回给请求者。
当我直接访问端点时,该文件就可以了。当我通过API网关访问它时,它会损坏。
损坏采用原始文件中字节的形式,被转换为0xEFBFBD
。这是UTF-8 'replacement character'。
我的请求已将Accept
设置为application/zip
,响应中有Content-Type: application/zip
。
我的期望是API网关应该将其识别为二进制媒体类型,而不管文件如何,但是很显然,它会将其作为文本内容进行处理。
我在做什么错了?
答案 0 :(得分:2)
将“二进制媒体类型”设置为“ multipart / form-data”对我来说解决了类似的问题。 看到这里:AWS Api Gateway as a HTTP Proxy is currupting binary uploaded image files