springboot中多线程中使用MultipartFile进行异步操作报错,系统找不到指定的文件

springboot中多线程中使用MultipartFile进行异步操作报错,系统找不到指定的文件

首先,前端传递的文件会存储在一个临时文件夹中,也就是这样的路径。[en]First of all, the files passed by the front end will be stored in a temporary folder, that is, a path like this.

<span class="hljs-selector-tag">C</span>:\<span class="hljs-selector-tag">Users</span>\<span class="hljs-selector-tag">xxx</span>\<span class="hljs-selector-tag">AppData</span>\<span class="hljs-selector-tag">Local</span>\<span class="hljs-selector-tag">Temp</span>\<span class="hljs-selector-tag">tomcat</span><span class="hljs-selector-class">.6131519677783180826</span><span class="hljs-selector-class">.8056</span>\<span class="hljs-selector-tag">work</span>\<span class="hljs-selector-tag">Tomcat</span>\<span class="hljs-selector-tag">localhost</span>\<span class="hljs-selector-tag">ROOT</span>

但在异步执行时,主线程结束,临时文件被清空,因此会报告错误:[en]But when executing asynchronously, the main thread ends and the temporary file is emptied, so an error is reported:

java.io.FileNotFoundException: C:\Users\hwq\AppData\Local\Temp\tomcat.6131519677783180826.8056\work\Tomcat\localhost\ROOT\upload_85d787c3_6037_4ea2_a7f9_54ac3a19b461_00000011.tmp (系统找不到指定的文件。)

需要转换为流才能运行[en]Need to be converted to a stream to operate

 @RequestMapping("/add")    public String addRecordDetail(@RequestParam("file") MultipartFile file, @ModelAttribute FormDetail formDetail) throws IOException {            String fileName = buildFileName(file);            InputStream inputStream = file.getInputStream();            RecordDetailThreadMange detailThreadMange = new RecordDetailThreadMange(inputStream,formDetail,fileName);            threadPoolService.addThreadPoolTask(detailThreadMange);            logger.debug("============>run next process,当前线程名称:{}",Thread.currentThread().getName());            return "true";    }

原文地址:https://blog.csdn.net/javadream007/article/details/102566585

Original: https://www.cnblogs.com/jpfss/p/12193163.html
Author: 星朝
Title: springboot中多线程中使用MultipartFile进行异步操作报错,系统找不到指定的文件

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6135/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部