如何使用micronaut-function-aws-api-proxy处理多部分/表单数据文件上传

时间:2019-04-04 23:47:02

标签: aws-lambda aws-api-gateway micronaut micronaut-aws

我在AWS API Gateway代理的Kotlin Lambda函数中使用micronaut 1.1.0.RC2micronaut-function-aws-api-proxy 1.1.0.RC3。除文件上传路径外,micronaut aws api代理对我的所有API函数均适用。类和路由定义看起来像这样:

@Controller("/things/{id}/attachments")
class AttachmentController {
    @Post(consumes = [MediaType.MULTIPART_FORM_DATA])
    fun post(request: HttpRequest<Any>, id: Int, file: CompletedFileUpload): Attachment? {
        ...
    }
}

在本地运行,可以正常工作。但是,当我通过API网关和Lambda使用它时,会不断出现以下错误:

ERROR c.a.s.p.AwsProxyExceptionHandler Called exception handler for:
io.micronaut.web.router.exceptions.UnsatisfiedRouteException: Required argument [CompletedFileUpload file] not specified
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:279)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:122)
...

同样,如果我在本地运行micronaut应用程序并直接访问API(没有micronaut AWS代理),它会完美运行。但是,当我将其部署到AWS时,micronaut aws代理似乎出现了一个问题,无法正确解析出多部分的表单数据。

我确实在API网关上将multipart/form-data设置为二进制媒体类型。我已经尝试使用CompletedFileUpload类型和StreamingFileUpload类型,如主要micronaut文档(https://docs.micronaut.io/1.1.0.RC2/guide/index.html)中所述,结果相同。

对于它的价值,我使用AWS Spark代理(aws-serverless-java-container-spark)对同一件事进行了不同的实现,并且可以正常运行。

要测试,我正在运行以下curl命令:

curl -X POST https://<host>/things/42/attachments -H 'content-type: multipart/form-data' -F file=@/path/to/file.png

其他人对此有好运吗?目前,micronaut api网关代理不支持它吗?任何帮助表示赞赏!

0 个答案:

没有答案