![](/img/trans.png)
[英]Spring Boot Multipart REST endpoint gives 'Current request is not a multipart request' when called from Postman
[英]Spring-boot rest api current request is not multipart request with postman
我在使用Postman在我的spring-boot應用程序中調用API時遇到問題。
錯誤Current request is not a multipart request
郵差: 郵差屏幕截圖大多數其他帖子都是由刪除標題的人修復的,這不是我的工作。
這是我的控制器:
@Controller
public class RestController {
@GetMapping("/upload/remote")
public ResponseEntity<?> handleFileUploadRemote(@RequestParam("file") MultipartFile file) {
return null;
}
}
這僅為測試目的返回null。
我也嘗試將其保留為@RequestMapping("/upload/remote")
。 關於這里可能出現什么問題的任何想法? 我遺漏了很多測試這個錯誤的邏輯。
更新1:我嘗試使用RequestPart("file")
而不是RequestParam("file")
,以及將GetMapping
轉換為RequestMapping
和PostMapping
以及上述更改。 我仍然得到相同的錯誤,但是,使用PostMapping我得到以下內容: Request method 'GET' not supported
編輯:如果我點擊Postman中的“代碼”選項,我會看到以下代碼:
POST /upload/remote HTTP/1.1
Host: localhost
cache-control: no-cache
Postman-Token: 30b67342-6e38-4f2e-8335-fb118d28bf50
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="C:\settings.xml
------WebKitFormBoundary7MA4YWxkTrZu0gW--
嘗試使用@RequestPart
而不是@RequestParam
,通常這樣的方法是POST。 所以嘗試使用
@PostMapping("/upload/remote")
public ResponseEntity<?> handleFileUploadRemote(@RequestPart("file") MultipartFile file) {
return null;
}
我的解決方案
@RequestMapping(value = ""/upload/remote"", method = RequestMethod.POST)
public void fileUplaod(MultipartFile file, HttpServletRequest request) {
return null;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.