AWS Api 作为 HTTP 代理的网关正在破坏二进制上传的图像文件
AWS Api Gateway as a HTTP Proxy is currupting binary uploaded image files
我在 rails 应用程序上有一个 ruby 可以获取图像文件 "attaches it to a member" 并将其上传到 s3。当我使用 insomnia 和 POST 直接到应用程序时...... 它有效 ,但是当我在 AWS Api 网关后面使用完全相同的端点时,图像是损坏且不可见。
这里是请求的对比
- LEFT = 直接发布到 rails 应用
- 右 = 通过 api 网关
https://www.diffchecker.com/wwUmpB5W
我注意到,回形针 gem 是 运行 不同的命令。很明显,回形针在通过 API 网关时意识到文件不是图像。
以下是一些可能相关的屏幕截图
这里是rails代码:
def create
logger.info 'upload_attachment_api_general_v1'
logger.info params
logger.info request.env
@file = current_merchant.members.find(params[:member_id]).attachments.new(file: params[:file], label: params[:label])
if params[:file] && @file.save
render json: @file
else
render json: @file.errors, status: :unprocessable_entity
end
end
我明白了。内容类型不是 image/png
...内容类型是 multipart/form-data
我在 rails 应用程序上有一个 ruby 可以获取图像文件 "attaches it to a member" 并将其上传到 s3。当我使用 insomnia 和 POST 直接到应用程序时...... 它有效 ,但是当我在 AWS Api 网关后面使用完全相同的端点时,图像是损坏且不可见。
这里是请求的对比
- LEFT = 直接发布到 rails 应用
- 右 = 通过 api 网关
https://www.diffchecker.com/wwUmpB5W
我注意到,回形针 gem 是 运行 不同的命令。很明显,回形针在通过 API 网关时意识到文件不是图像。
以下是一些可能相关的屏幕截图
这里是rails代码:
def create
logger.info 'upload_attachment_api_general_v1'
logger.info params
logger.info request.env
@file = current_merchant.members.find(params[:member_id]).attachments.new(file: params[:file], label: params[:label])
if params[:file] && @file.save
render json: @file
else
render json: @file.errors, status: :unprocessable_entity
end
end
我明白了。内容类型不是 image/png
...内容类型是 multipart/form-data