Springboot文件上传报java.nio.file.NoSuchFileException: /tmp/undertow
文章目录
今天测试环境有个问题,文件上传报错了。java.nio.file.NoSuchFileException: /tmp/undertow
查了下,是临时文件目录被删除了,做一下笔记。
首先是临时文件目录
windows C:\Users{username}\AppData\Local\Temp\
Linux /tmp
Springboot在上传文件时,会把文件存在这两个路径上。以window为例子,在代码里打断点。

前端点上传时进断点,这时去临时文件夹看。

出现了undertow开头,upload结尾的临时文件,这个文件在请求结束后就被删除了。
如果你把临时目录删了,再上传文件,就会报标题的错误。

这时要么重启项目,要么在springboot上做配置,该配置转载于
https://my.oschina.net/648885...
@Configuration
public class MultipartConfig {
@Value("${配置文件 中指定一个目录}")
private String locationTemp;
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
File tmpFile = new File(locationTemp);
if (!tmpFile.exists()) {
tmpFile.mkdirs();
}
factory.setLocation(locationTemp);
return factory.createMultipartConfig();
}
}或者
spring.servlet.multipart.location=/tmp/undertow
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论