Spring MVC file upload via MultipartFile gives sometimes(!) empty InputSteam
we encountered a strange problem with our simple file upload system.
The setup is: Spring 3.2.2, commons fileupload 1.3, commons io 2.4. We're actually running straight from Eclipse with an external Tomcat 7.0.40. It's been tested on Mac OS X 10.8 and 10.6.
Here's the code:
public void saveFile(MultipartFile file, String description) {
System.out.println(file.getOriginalFilename());
System.out.println(file.getSize());
OutputStream out = new FileOutputStream("someFileName");
IOUtils.copy(file.getInputStream(), out);
out.flush();
out.close();
}
It outputs the correct file name and also the correct file size!
Now when it comes to writing the file to disk, it produces a 0 byte file. This especially happens with .docx
files (in about 95% of the cases). It seems to depend on the file. Images and PDF documents seem to work always.
There's no exception or any other hint. The debugger says that the InputStream
is empty (not null
, just empty).
Any explanation for this behaviour?
I would check the following:
上一篇: okhttp登录拦截器在多部分