通过AWS API Gateway发布表单数据和二进制数据 [英] Posting form-data and binary data through AWS API Gateway

查看:152
本文介绍了通过AWS API Gateway发布表单数据和二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过AWS API Gateway将"mutlipart \ form-data"发布到我的EC2实例,但是我找不到解决方法.有一种方法可以使用"application/x-www-form-urlencoded"和Mapping Tamplate发布数据以将其转换为JSON,但是我想仍然缺少像图像文件这样的二进制数据.我有什么想念的吗?

I'm trying to POST "mutlipart\form-data" to my EC2 instance through AWS API Gateway, but I couldn't find a way to this. There is a way to post data using "application/x-www-form-urlencoded" and Mapping Tamplate to convert it to JSON but still posting a binary data like an image file is missing I guess. Is there anything I'm missing ?

我找到了另一种方法:

我将图像转换为base64字符串,然后将其发布为内容类型为"application/x-www-form-urlencoded".通过这种方式,我将整个图像作为字符串发送.收到消息后,我可以将其转换回PHP中的图像.我只能发现,当我将图像转换为base64时,它的大小会变大一些.除此之外,我找不到其他缺点.如果可以,请与我分享?

I convert the image to base64 string then POST it as with content type "application/x-www-form-urlencoded". By this way I'm sending whole image as string. After I got the message I can convert it back to image in PHP. Only down side of this I could find is when I convert image to base64 its size gets a bit bigger. Other than that, I couldnt find any other downside. If there is could you please share with me ?

推荐答案

此处是Api Gateway团队.

Api Gateway team here.

目前不支持二进制数据,但已将其保存在我们的积压中.有几个客户要求这样做.

一些客户在映射模板中成功使用了base64 util,这可能会使它为您工作:

Some customers have had success using the base64 util in the mapping templates which may get it working for you: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#util-template-reference

除此之外,您还必须等待官方支持.

Other than that you'll have to wait for official support.

修改

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆