|
@@ -4,6 +4,8 @@ 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 org.springframework.util.unit.DataUnit;
|
|
|
|
|
|
import javax.servlet.MultipartConfigElement;
|
|
|
|
|
@@ -13,6 +15,10 @@ public class MulitpartConfig {
|
|
|
|
|
|
@Value("${spring.profiles.active}")
|
|
|
private String env;
|
|
|
+ @Value("${spring.servlet.multipart.max-file-size}")
|
|
|
+ private String maxFileSize;
|
|
|
+ @Value("${spring.servlet.multipart.max-request-size}")
|
|
|
+ private String maxRequestSize;
|
|
|
/**
|
|
|
* 文件上传临时路径
|
|
|
*/
|
|
@@ -24,7 +30,24 @@ public class MulitpartConfig {
|
|
|
} else {
|
|
|
factory.setLocation("/app");
|
|
|
}
|
|
|
+ DataUnit unit = DataUnit.MEGABYTES;
|
|
|
+ long longMaxFileSize = 10L;
|
|
|
+ long longMaxRequestSize = 10L;
|
|
|
+ if (maxFileSize.contains("MB")) {
|
|
|
+ longMaxFileSize = Long.parseLong(maxFileSize.replace("MB", ""));
|
|
|
+ longMaxRequestSize = Long.parseLong(maxRequestSize.replace("MB", ""));
|
|
|
+ } else if (maxFileSize.contains("GB")) {
|
|
|
+ unit = DataUnit.GIGABYTES;
|
|
|
+ longMaxFileSize = Long.parseLong(maxFileSize.replace("GB", ""));
|
|
|
+ longMaxRequestSize = Long.parseLong(maxRequestSize.replace("GB", ""));
|
|
|
+ } else if (maxFileSize.contains("TB")) {
|
|
|
+ unit = DataUnit.TERABYTES;
|
|
|
+ longMaxFileSize = Long.parseLong(maxFileSize.replace("TB", ""));
|
|
|
+ longMaxRequestSize = Long.parseLong(maxRequestSize.replace("TB", ""));
|
|
|
+ }
|
|
|
|
|
|
+ factory.setMaxFileSize(DataSize.of(longMaxFileSize, unit));
|
|
|
+ factory.setMaxRequestSize(DataSize.of(longMaxRequestSize, unit));
|
|
|
return factory.createMultipartConfig();
|
|
|
}
|
|
|
|