MultipartResolver is not working

≯℡__Kan透↙ 提交于 2020-01-13 11:13:12

问题


I using developing a RESTFul web service using Maven and Spring Roo.

In my configuration xml file I defined a multipartResolver bean because I am uploading files of 300KB:

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="400000" />
    <property name="maxInMemorySize" value="400000" />
</bean>

The files are uploaded successfully and pushed into a stack. These file are CommonsMultipartFile or MultipartFile objects (I have the same phenomenon for both type of objects). Once I pop a file, I can call getSize() method and I can verify that the size of the file is correct. But once I call getInputStream() I get the following error: File has been moved - cannot be read again.

Did I do something wrong in my multipartResolver declaration? Is there any other reason to have this error?

Thank you


回答1:


The call to getInputStream() is being recognized as a request to get the input stream of the file on the client-side. And as the file has been already uploaded it says "file has been moved - cannot read again"

also what are you trying to do by calling getInputStream()? If you want to read the uploaded file, create a new FileInputStream with the path of the uploaded location and access the file contents.



来源:https://stackoverflow.com/questions/11792107/multipartresolver-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!