Spring boot 文件上传commons-fileupload

时间:2024-02-26 09:55:59

错误返回:

Required request part \'file\' is not present

请检查你是否引入了这个jar包

自带了upload files的配置

1.如果没有

上传文件时需要引入并在webMvc配置

       <!-- fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.3</version>
        </dependency>

没有上面jar包时需要引入

 

 @Bean
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        multipartResolver.setMaxUploadSize(environment.getProperty("file.upload.max.size", Long.class, 104857600L));
        return multipartResolver;
    }