org.springframework.web.multipart.MultipartException: The current request is not a multipart request

前端 未结 3 893
轮回少年
轮回少年 2020-12-14 15:09

I am trying to send a multipart request to the server but i am getting the following exception HTTP Status 500 - Request processing failed; nested exception is org.spring

相关标签:
3条回答
  • 2020-12-14 15:39

    It seems that your tag form is not well formated and everything that is after the

    'action="<c:url value="/members/profileimageupload" />"' 
    

    is being ignored. Try to write like this and see if it works:

    action="<c:url value='/members/profileimageupload' />"
    
    0 讨论(0)
  • 2020-12-14 15:47

    Check whether you have added CommonsMultipartResolver in Spring-Servlet.xml.

        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
    

    Then, add the enctype to multipart/form-data in your form

    <form id="fileupload" method="post" enctype="multipart/form-data">
    

    Finally in Controller, Request > MultipartHttpServletRequest

     @RequestMapping(value = "/profileimageupload", method = RequestMethod.POST)
    public ModelAndView uploadProfileImage(MultipartHttpServletRequest request) {}
    

    Dependencies

    1. commons-fileupload.jar
    2. commons-io.jar
    0 讨论(0)
  • 2020-12-14 15:51

    Try again with "headers":

    @RequestMapping(value = "/profileimageupload", headers = "content-type=multipart/*", method = RequestMethod.POST)
    

    and ajax call follow: How can I upload files asynchronously?

    I hope this helpful to you!

    0 讨论(0)
提交回复
热议问题