【发布时间】:2021-05-10 03:54:56
【问题描述】:
我正在用 Java 编写 AWS lambda。此 lambda 充当 APIGatewayProxyRequestEvent 的处理程序。
API 网关端点正在将文件作为正文中的 multipart/form-data 发送。
public class LambdaHandler extends SpringBootRequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
---
}
在尝试实现业务逻辑时,我首先将正文提取到一个字节数组中
byte[] file = Base64.decodeBase64(event.getBody().getBytes());
但是当我将这些字节写入字符串以从中提取数据时,我得到以下信息:
log.info("file content : {}", new String(file));
output:
----------------------------728667852190241466147817
Content-Disposition: form-data; name=""; filename="testuplode.json"
Content-Type: application/json
this is a test file
----------------------------728667852190241466147817--
如何从多部分文件的字节流中获取文件的唯一内容?
【问题讨论】:
-
正在寻找一种在 AWS Lambda 等无服务器环境中执行此操作的方法。 AWS lambda 是否提供这样的处理程序?
-
@SwapnilKhante AWS 没有为此提供处理程序。但是,我确实找到了解决方案 - 发布在原始问题 stackoverflow.com/a/65279215/3866010
标签: java aws-lambda spring-cloud-function