解决使用Spring Boot、Multipartfile上传文件路径错误问题

  • 报错信息: java.io.IOException: java.io.FileNotFoundException: /tmp/tomcat.273391201583741210.8080/work/Tomcat/localhost/ROOT/tmp/source/IMG_20160129_132623.jpg (No such file or directory)

问题源码: transferTo方法报错

// 前端传入mulFileSource
// 创建压缩前源文件
File fileSourcePath = new File("tmp/source/");
File fileSource = new File(fileSourcePath, mulFileSource.getOriginalFilename());
if (!fileSourcePath.exists()) {
    fileSourcePath.mkdirs();
}
// 将接收得图片暂存到临时文件中
mulFileSource.transferTo(fileSource);

 

posted @ 2019-01-17 15:07  爱吃醋的工程师  阅读(5551)  评论(0编辑  收藏  举报