- 相对路径
spring.servlet.multipart.location=app/tmpfiles # 使用相对路径
注意没有./表示当前目录的写法
2. 绝对路径
spring.servlet.multipart.location=/tmp/app/tmpfiles # 使用绝对路径
- 默认地址,可不配
spring.servlet.multipart.location= ${java.io.tmpdir}
- 通过启动参数可以改变该行为;覆盖默认-Djava.io.tmpdir=/path/to/tmpdir
spring.servlet.multipart.location= ${java.io.tmpdir}
默认地址说明
- Windows:
C:\Users\{用户名}\AppData\Local\Temp - Solaris:
/var/tmp/ - Linux:
/tmp - Mac OS X:
/tmp
tomcat上传文件存储路径
// org.apache.catalina.connector.Request
File location;
// 获取配置的文件路径spring.servlet.multipart.location
String locationStr = mce.getLocation();
//为空时使用系统默认的临时文件路径
if (locationStr == null || locationStr.length() == 0) {
location = ((File) context.getServletContext().getAttribute(
ServletContext.TEMPDIR));
} else {
// 如果是绝对路径直接使用;相对路径以临时文件夹为基准,自动创建对应路径的文件路径
location = new File(locationStr);
if (!location.isAbsolute()) {
location = new File(
(File) context.getServletContext().getAttribute(ServletContext.TEMPDIR),
locationStr).getAbsoluteFile();
}
}
本文介绍如何配置 Spring MVC 中的大文件上传路径,包括使用相对路径和绝对路径的方法,并解释了默认路径设置及如何通过启动参数改变默认行为。
1023

被折叠的 条评论
为什么被折叠?



