0

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?

Benjamin M
  • 23,599
  • 32
  • 121
  • 201

1 Answers1

0

I would check the following:

  • Does your server has any antivirus / malware software that prevents unknown program to write docx into the filesystem.
  • Does the OS user that runs your server (hence writes the file to FS) has sufficient permission to do so?
  • InputStream empty could means the uploaded document starts with EOF. Also check the content of the docx itself maybe it's corrupted / some file encoding problem causes multibyte character interpreted as EOF. I would probably debug the docx by printing first few bytes in hex
gerrytan
  • 40,313
  • 9
  • 84
  • 99
  • it's no permission problem, since everything works with images and pdf. And even *some* docx are working nice, but most of them just get saved as 0 byte files. And I don't think that there is any anti virus software. At least on my dev system there is none and the problem remains. – Benjamin M Jun 17 '13 at 23:28