[英]How to extract body and file name from mulitpart file?
我正在用 Java 編寫 AWS lambda。 此 lambda 充當APIGatewayProxyRequestEvent
的處理程序。
API 網關端點正在將文件作為多部分/表單數據發送到正文中。
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--
如何從多部分文件的字節流中獲取文件的唯一內容?
我發現在使用 Java 時使用 AWS Lambda 處理多部分文件的最佳解決方案是使用 Spring 雲函數。 請檢查以下 GitHub 票證以確認功能可用性:
https://github.com/spring-cloud/spring-cloud-function/issues/597
但是,我還設法使用低級 API 使用核心 java 編寫代碼,因為該功能在我需要時無法使用。 我參考了這個博客。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.