文件上传 ,java.lang.IllegalStateException: File has been moved - cannot be read again org.springframewor

来源:互联网 发布:浙江软件考试成绩查询 编辑:程序博客网 时间:2024/06/10 18:13

启动新线程进行文件上传 报:,java.lang.IllegalStateException: File has been moved - cannot be read again org.springframewor错误

查看多媒体文件上传处理类支持的上传大小设置合理

<!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1024(B)=10485760 bytes -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="${web.maxUploadSize}" />
</bean>

查看源码:

@Override

public void transferTo(File dest) throws IOException, IllegalStateException {
if (!isAvailable()) {
throw new IllegalStateException("File has already been moved - cannot be transferred again");
}

....
}

文件是否合法,

protected boolean isAvailable() {
// If in memory, it's available.
if (this.fileItem.isInMemory()) {
return true;
}
// Check actual existence of temporary file.
if (this.fileItem instanceof DiskFileItem) {
return ((DiskFileItem) this.fileItem).getStoreLocation().exists(); 在此返回false
}
// Check whether current file size is different than original one.
return (this.fileItem.getSize() == this.size);
}

这是说明该文件不存在,为什么会出现不存在呢?

如果我不用新的线程上传文件,则不会出现该问题.

为什么在新的线程中上传文件出现该问题?



0 0