[英]Spring-boot rest api current request is not multipart request with postman
[英]Spring Boot Multipart REST endpoint gives 'Current request is not a multipart request' when called from Postman
Spring 引導版本:2.1.5.RELEASE。 Spring 雲版:Greenwich.RELEASE
我在 class 注釋@Controller
中定義了以下端點
@PostMapping("/")
@ResponseBody
public OcrResponse submitFile(@RequestParam("file") MultipartFile multipartFile) {
logger.info("Entering submitFile method");
//do more stuff......
}
我正在使用 Postman 對其進行測試,它工作正常。 昨天,我決定將 Postman 更新到最新版本(距離我更新它可能至少一年)。 現在,當我測試它時,我收到以下錯誤:-
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:194)
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:113)
這就是我的 Postman 請求的樣子:-
我已經看到其他具有類似錯誤的帖子,但這些大多已通過從請求中刪除 Content-type header 來解決,但在這種情況下不起作用。
我嘗試刪除、重命名和重新排序 Postman 標頭,但這些都沒有幫助。 我還嘗試更改 REST 端點方法簽名,例如重命名 MultipartFile 變量和參數以及使用 RequestPart 而不是 RequestParam,但到目前為止沒有任何效果。 似乎很奇怪,完全相同的請求適用於舊版本的 Postman。 我將非常感謝任何指導/建議。
以防萬一它對其他人有幫助,我正在分享我是如何解決這個問題的......
當我安裝了舊版本的 Postman 並通過“設置”->“更新”菜單將該安裝版本更新到最新版本時,就會出現上述問題。
從那以后,我完全卸載了 Postman 並從頭開始安裝最新版本。 現在問題已經消失,我可以成功測試我的端點。 有點奇怪,但至少它已經解除了我的障礙。
因此,我對任何升級 Postman 安裝的人的建議是避免嘗試更新現有安裝。 相反,導出所有 collections,完全卸載舊版本,從頭開始安裝新版本並重新導入所有 collections。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.