SpringMVC-FileUpload - The request sent by the client was syntactically incorrect

后端 未结 1 821
太阳男子
太阳男子 2021-01-24 15:21

I\'ve seen couple of qts on the same topic. But I didn\'t find any clue of this error.

I am working on a POC and following the link below. http://spring.io/guides/gs/upl

相关标签:
1条回答
  • 2021-01-24 15:26

    There are 2 things you need to do:

    First, add the Apache Commons FileUpload library to your class path. If you use maven, you can get the dependency here. If you don't, you can still download the jar and add it manually.

    Second, you have to declare a MultipartResolver bean in your context with name multipartResolver. With Apache Commonds FileUpload, you can use CommonsMultipartResolver. For example, with Java config, that would be

    @Bean(name = "multipartResolver")
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(); 
        // set any fields
        return commonsMultipartResolver; 
    }
    

    With XML config,

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    
        <!-- set any properties -->
    </bean>
    

    This is further documented in the Spring official documentation.

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