Spring上传文件路径配置

  1. 相对路径
spring.servlet.multipart.location=app/tmpfiles # 使用相对路径

注意没有./表示当前目录的写法
2. 绝对路径

spring.servlet.multipart.location=/tmp/app/tmpfiles # 使用绝对路径
  1. 默认地址,可不配
spring.servlet.multipart.location= ${java.io.tmpdir}
  1. 通过启动参数可以改变该行为;覆盖默认-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();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值