我想使用 AWS API Gateway 在我的网站上显示 S3 存储桶中的图像。我按照 AWS 的本手册进行操作:如何通过 API Gateway 将图像或 PDF 文件上传到 Amazon S3?
如果我想使用网络浏览器显示图像(从API网关链接到图像),网络浏览器会下载一些无法显示的奇怪图像。当我使用 Postman 时,图像显示没有任何问题。我尝试从网络浏览器下载图像,但无法显示。从 Postman 下载的图像按预期工作。
使用 API Gateway 上传文件没有问题,因为它不会在浏览器中显示我直接上传到 S3(使用 AWS 控制台)的图像。
API网关设置:
Method Execution
-> Integration Request
已设置
Content Handling
至 Passthrough
。Method Execution
-> Method Response
中的 GET 方法中,在 Http Status 200 下设置:Access-Control-Allow-Origin
、Content-type
Http Status 200
下的 GET 方法中设置:Access-Control-Allow-Origin
至 '*'
,Content-type
至 'image/jpeg'
在
Binary Media Type
下的API设置中设置image/jpeg
在 Postman 和 Web 浏览器中的开发工具 -> 网络中,当我单击 API Gateway 中的图像时,标题为:
Accept:
image/jpeg
Content-Type:
image/jpeg
Access-Control-Allow-Origin:
*
注意: Api Gateway 部署到最新版本,CORS 没有问题(CORS 已启用) 如果您需要更多信息,请告诉我。
更新: 最近我尝试重新创建 GET 请求。它不是在手册中编写的,但是当我将标题添加到
Method Response
下的Response Header for 200
和Accept
下的Integration Response
中时,我设置了Header Mappings
Accept
图像正确地显示在Postman中,而不是它