MultipartResolver不起作用 [英] MultipartResolver is not working
问题描述
使用Maven和Spring Roo开发一个RESTFul Web服务。
在我的配置xml文件中,我定义了一个 multipartResolver
bean,因为我正在上传300KB的文件:
< bean id =multipartResolverclass =org.springframework .web.multipart.commons.CommonsMultipartResolver>
< property name =maxUploadSizevalue =400000/>
< property name =maxInMemorySizevalue =400000/>
< / bean>
成功上传文件并将其压入堆栈。这些文件是 CommonsMultipartFile
或 MultipartFile
对象(我对这两种类型的对象都有相同的现象)。一旦我弹出一个文件,我可以调用 getSize()
方法,我可以验证文件的大小是否正确。但是,一旦我调用 getInputStream()
,我得到以下错误:文件已被移动 - 无法再读取。
/ p>
在我的 multipartResolver
声明中做错了什么?有没有其他原因有这个错误?
谢谢
<对getInputStream()的调用被认为是获取客户端文件的输入流的请求。而且,由于文件已经上传,它说文件已被移动 - 不能再读
你也试图通过调用getInputStream()?如果您想读取上传的文件,请使用上传位置的路径创建一个新的FileInputStream并访问文件内容。
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
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.
这篇关于MultipartResolver不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!