惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - 星朝

博客园搬家 窗口函数详细用法 JVM启动参数大全 BigDecimal.setScale用法总结 - 星朝 - 博客园 springboot中多线程中使用MultipartFile进行异步操作报错,系统找不到指定的文件 java获取本机IP Java获取本机ip和服务器ip Spring中的@Transactional(rollbackFor = Exception.class)属性详解 注解@CrossOrigin解决跨域问题 unique key index区别 mysql 创建唯一约束表 MySQL中添加唯一约束和联合唯一约束 移动IM开源框架Tigase > Openfire > Ejabberd对比分析 Tigase 8.0开发环境搭建 Tigase手动安装过程 几个时序数据库 时序数据库入门 MySQL执行计划extra中的using index 和 using where using index 的区别 ETL的详细解释定义
springboot项目上传文件出现临时文件目录为空
星朝 · 2020-01-14 · via 博客园 - 星朝

最近写文件上传到服务器读取的代码,前端使用FormData上传,服务端用MultipartFile接收,自己测试了下MultipartFile对象有什么东西,结果一般属性都能出来,测试getInputStrea()方法的时候出现了以下错误,简单一看这是什么目录,从来没见过啊:

百度一番之后发现了这是临时文件存放的路径,不清楚根据什么去放在这个目录的,但是这个目录本机的确没有,linux系统下好像系统会10天清空一次,翻阅了API底下有这个

百度的时候也发现另外一个坑,spring配置的

@Bean
public MultipartConfigElement multipartConfigElement(){
MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();
String location = System.getProperty("user.dir") + "/data/tmp";
File file = new File(location);
if(!file.exists()){
file.mkdirs();
}
multipartConfigFactory.setLocation(location);
return multipartConfigFactory.createMultipartConfig();
}

然后debug了下,发现getInputStream()中的path就是我设置的了:

如果设置了大小,设置了路径还是不行,可以把MultipartFile设置为File做操作

最后说句,代码不懂得一定要看API,一下子就豁然开朗了