| 
				
				
				
				 | 
			
			 | 
			@@ -0,0 +1,52 @@ | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			package com.iformall.config; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			import java.io.File; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			import javax.servlet.MultipartConfigElement; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			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 lombok.extern.slf4j.Slf4j; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			@Slf4j | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			@Configuration | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			public class MultipartConfig { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				@Value("${spring.servlet.multipart.location}") | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				private String fileTempDir; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				@Value("${spring.servlet.multipart.max-file-size}") | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				private String maxFileSize; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				@Value("${spring.servlet.multipart.max-request-size}") | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				private String maxRequestSize; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				@Bean | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				MultipartConfigElement mulitipartConfigElement() { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					String os  = System.getProperty("os.name"); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					if (os.toLowerCase().startsWith("win")) { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
						fileTempDir = "C:" + fileTempDir; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					log.info("fileTempDir:{}",fileTempDir); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					MultipartConfigFactory factory = new MultipartConfigFactory(); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					File tmpDirFile = new File(fileTempDir); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					if (!tmpDirFile.exists()) { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
						boolean mkdirSuccess = tmpDirFile.mkdirs(); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
						log.info(" create temp dir, result:{}",mkdirSuccess); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					factory.setLocation(fileTempDir); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					factory.setMaxFileSize(DataSize.parse(maxFileSize)); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					factory.setMaxRequestSize(DataSize.parse(maxRequestSize)); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					return factory.createMultipartConfig(); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				public static void main(String[] args) { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
					System.out.println(DataSize.parse("50MB")); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
				 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			} |