SpringMVC上傳文件異常 400 - Required MultipartFile parameter 'files' is not present postman


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>

再啟動,搞定可以進了。




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM