SpringMVC上傳檔案異常 400 - Required MultipartFile parameter 'files' is not present postman
阿新 • • 發佈:2021-11-24
SpringMVC上傳檔案異常 400 -
Required MultipartFile parameter 'files' is not present
在寫一個api的介面,上傳檔案,型別為:MultipartFile。
用postman想請求一下一直報錯,不進斷點。
Required MultipartFile parameter 'files' is not present
1.先檢查postman的設定
型別:post
body選form-data
檢查head的Content-Type的值multipart/form-data
檢查body的入參名稱files ,型別要選file不是text,value選擇一個上傳的檔案
點發送
2.檢查程式碼的
controller的
method = RequestMethod.POST
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST) public void uploadFile(@RequestParam(value = "files") MultipartFile files)
注意
@RequestParam
檢查完以上後,postman點發送還是不行不進斷點。報錯Required MultipartFile parameter 'files' is not present
----
高能
要注意一下spring mvc的掃描 spring-mvc.xml的配置檔案中加了以下配置
加上這個
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding"> <value>UTF-8</value> </property> <property name="maxUploadSize"> <value>32505856</value><!-- 上傳檔案大小限制為31M,31*1024*1024 --> </property> <property name="maxInMemorySize"> <value>4096</value> </property> </bean>
再啟動,搞定可以進了。