diff --git a/cloud-common/src/main/java/com/cm/common/config/WebConfig.java b/cloud-common/src/main/java/com/cm/common/config/WebConfig.java index 8136097..1bda5f4 100644 --- a/cloud-common/src/main/java/com/cm/common/config/WebConfig.java +++ b/cloud-common/src/main/java/com/cm/common/config/WebConfig.java @@ -2,11 +2,16 @@ package com.cm.common.config; import com.cm.common.config.properties.FileProperties; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.MultipartConfigFactory; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import javax.servlet.MultipartConfigElement; +import java.io.File; + /** * @ClassName: WebConfig * @Description: Web配置 @@ -30,4 +35,16 @@ public class WebConfig implements WebMvcConfigurer { registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileProperties.getUploadPath()); registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/static/assets/").setCachePeriod(7 * 24 * 3600); } + + @Bean + public MultipartConfigElement multipartConfigElement(){ + MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory(); + String location = System.getProperty("user.dir") + "/data/tmp"; + File file = new File(location); + if(!file.exists()){ + file.mkdirs(); + } + multipartConfigFactory.setLocation(location); + return multipartConfigFactory.createMultipartConfig(); + } }