异步方法上传MultipartFile问题

3 篇文章 0 订阅
1 篇文章 0 订阅

异步方法上传MultipartFile问题

环境概述

前端上传Excel文件,后端通过Spring的MultipartFile对象接收。

问题现象

本地环境始终可以,线上环境偶尔可以。偶尔的报错提示如下

java.io.FileNotFoundException: /tmp/tomcat.6000477750703684958.8120/work/Tomcat/localhost/ROOT/upload_03540bf9_3ae6_4233_af15_cd87c5bacebf_00000000.tmp (No such file or directory)

原因解析

官方源码注释如下:

/**
 * A representation of an uploaded file received in a multipart request.
 *
 * <p>The file contents are either stored in memory or temporarily on disk.
 * In either case, the user is responsible for copying file contents to a
 * session-level or persistent store as and if desired. The temporary storage
 * will be cleared at the end of request processing.
 *
 * @author Juergen Hoeller
 * @author Trevor D. Cook
 * @since 29.09.2003
 * @see org.springframework.web.multipart.MultipartHttpServletRequest
 * @see org.springframework.web.multipart.MultipartResolver
 */

本人理解(自行翻译):

请求中收到的文件的,文件内容存储在内存中或临时存储在磁盘上。 *在任何一种情况下,用户都有责任根据需要将文件内容复制到会话级或持久性存储中。临时存储将在请求处理结束时清除。

所以呢?所以要保存处理或转文件对象。是不是解决了?是不是so easy?

解决方案

知道原因了,解决方案就多了。
我的解决方案是:将MultipartFile对象转化为File对象。

怎么转?请自行百度,方案太多了。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值