[每日一记]2022-08-19

 一、MultipartFile 上传文件临时目录自动清理机制隐患

1、默认存储在/tmp下,  但是linux的/tmp有自动清理的机制,

cat /usr/lib/tmpfiles.d/tmp.conf#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.# See tmpfiles.d(5) for details# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp

 2、改变默认位置

采用配置类:

@Configuration
public class MultipartConfig {/*** 文件上传临时路径*/@BeanMultipartConfigElement multipartConfigElement() {MultipartConfigFactory factory = new MultipartConfigFactory();String location = "自定义临时文件路径";File tmpFile = new File(location);if (!tmpFile.exists()) {tmpFile.mkdirs();}factory.setLocation(location);return factory.createMultipartConfig();}
}

配置文件方式:

#指定multipartFile临时文件存放路径,但是内置的tomcat创建的临时文件夹路径还是不变的
spring.servlet.multipart.location=临时文件路径
#指定springboot启动时内置tomcat创建的临时文件夹的路径
#server.tomcat.basedir=/data/ops/app/cms/cache

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部