先写配置类
package com
.file
.server
.config
;
import org
.springframework
.beans
.factory
.annotation
.Value
;
import org
.springframework
.boot
.web
.servlet
.MultipartConfigFactory
;
import org
.springframework
.context
.annotation
.Bean
;
import org
.springframework
.context
.annotation
.Configuration
;
import org
.springframework
.util
.unit
.DataSize
;
import javax
.servlet
.MultipartConfigElement
;
@Configuration
public class FileConfig {
@Value("${spring.server.MaxFileSize}")
private String MaxFileSize
;
@Value("${spring.server.MaxRequestSize}")
private String MaxRequestSize
;
@Bean
public MultipartConfigElement
multipartConfigElement() {
MultipartConfigFactory factory
= new MultipartConfigFactory();
factory
.setMaxFileSize(DataSize
.parse(MaxFileSize
));
factory
.setMaxRequestSize(DataSize
.parse(MaxRequestSize
));
return factory
.createMultipartConfig();
}
}
在application.yml中配置,然后重启服务
spring
:
server
:
MaxFileSize
: 200MB
MaxRequestSize
: 400MB
转载请注明原文地址: https://mac.8miu.com/read-514256.html