[英]Spring Boot 2.0.2 MultipartConfigElement not being configured for MultipartFile
我正在使用 Spring Boot 2.0.2.RELEASE ,並且無法為 REST 控制器端點上傳文件。
在這個入門之后,它說:
作為自動配置 Spring MVC 的一部分,Spring Boot 將創建一個 MultipartConfigElement bean 並為文件上傳做好准備。
因此,理論上,它應該在沒有任何額外配置的情況下工作,但看起來這個MultipartConfigElement
根本沒有被配置。
我收到這個警告:
WARN .a.w.r.e.DefaultErrorWebExceptionHandler: Failed to handle request [POST http://localhost:8080/upload]: Response status 400 with reason "Required MultipartFile parameter 'file' is not present"
我的 Spring 應用程序啟動器非常簡單:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
我的終點是:
@RestController
public class MyController {
@PostMapping("/upload")
public String hash(@RequestParam("file") MultipartFile file) {
final String test = file.getContentType();
}
我還確保取消標記郵遞員設置的任何默認內容類型,但沒有成功。 我可能做錯了什么?
首先,將其添加到您的屬性文件中
servlet.multipart.enabled=true servlet.multipart.max-file-size=20M
並將 CommonsMultipartResolver bean 創建為 (name = "multipartResolver")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.