问题描述
我有一个ruby on rails应用程序,该应用程序获取一个图像文件,将其附加到成员",然后将其上传到s3.当我将失眠和POST直接用于应用程序时... 它可以工作,但是,当我在AWS Api Gateway后面使用完全相同的终端节点时,该映像已损坏且无法查看.
I have a ruby on rails app that takes an image file, "attaches it to a member", and uploads it to s3. When I use insomnia and POST directly to the app ... it works, however when I use the exact same endpoint behind AWS Api Gateway, the image is corrupt and not viewable.
以下是请求的比较.
- LEFT =直接发布到Rails应用
- RIGHT =通过api网关
https://www.diffchecker.com/wwUmpB5W
我注意到的是回形针gem正在运行不同的命令.很明显,回形针意识到通过API网关传递文件时,该文件不是图像.
Something I noticed, is that the paperclip gem is running different commands. It's evident that paperclip realized that the file is not an image when being passed through API gateway.
以下是一些可能相关的屏幕截图
这是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
I figured it out. The content type is NOT an image/png
... the content type is multipart/form-data
这篇关于AWS Api Gateway作为HTTP代理正在破坏二进制上传的图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!