eladmin/eladmin-common/src/main/java/me/zhengjie/config/webConfig/MultipartConfig.java

47 lines
1.6 KiB
Java

/*
* Copyright 2019-2025 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.config.webConfig;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.MultipartConfigElement;
import java.io.File;
/**
* @date 2018-12-28
* @author <a href="https://blog.csdn.net/llibin1024530411/article/details/79474953">...</a>
*/
@Configuration
public class MultipartConfig {
/**
* 文件上传临时路径
*/
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
String location = System.getProperty("user.home") + "/.eladmin/file/tmp";
File tmpFile = new File(location);
if (!tmpFile.exists()) {
if (!tmpFile.mkdirs()) {
System.out.println("create was not successful.");
}
}
factory.setLocation(location);
return factory.createMultipartConfig();
}
}