1. 程式人生 > >Spring boot 檔案上傳commons-fileupload

Spring boot 檔案上傳commons-fileupload

錯誤返回:

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;
    }