Browse Source

上传文件大小手工配置注入

FengChaoYu 3 months ago
parent
commit
e46df0f10e

+ 2 - 4
mall-miniapp-service/src/main/resources/bootstrap.properties

@@ -12,10 +12,8 @@ wechat.keyPath=classpath:/static/apiclient_cert.p12
 
 #��������
 server.servlet.context-path=/zfdminiapp
-spring.servlet.multipart.enabled=true
-spring.servlet.multipart.max-file-size=40MB
-spring.servlet.multipart.max-request-size=50MB
-spring.servlet.multipart.file-size-threshold=0
+spring.servlet.multipart.max-file-size=100MB
+spring.servlet.multipart.max-request-size=120MB
 #�Ƿ�ֱ��web�˴�ӡ������Ϣ
 spring.devtools.add-properties=true
 #echache����

+ 23 - 0
mall-server-api/src/main/java/com/gree/mall/manager/config/MulitpartConfig.java

@@ -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();
     }
 

+ 2 - 2
mall-server-api/src/main/resources/bootstrap.properties

@@ -13,8 +13,8 @@ goods.share.limit.percent=0.4
 #��������
 server.port =23003
 server.servlet.context-path=/zfdapi
-spring.servlet.multipart.max-file-size=40MB
-spring.servlet.multipart.max-request-size=40MB
+spring.servlet.multipart.max-file-size=100MB
+spring.servlet.multipart.max-request-size=120MB
 #�Ƿ�ֱ��web�˴�ӡ������Ϣ
 spring.devtools.add-properties=true
 #echache����