Spring controller adds extra data to uploaded file

Viewed 39

I'm trying to refactor a servlet into a Spring REST controller but I'm having an issue with file uploads.

The servlet uses ServletFileUpload and FileItem. I have reused the same code for the Spring controller but when retrieving the bytes it seems like there is extra data (~10k).

When printing the file to the browser I get an error because the file is corrupted. I can't figure out where the extra bytes are coming from.

Here is the code:

FileItem item = ...

BufferedInputStream buff = new BufferedInputStream(item.getInputStream());
byte[] bytes = new byte[buff.available()];
buff.read(bytes, 0, bytes.length);

When executed from the servlet bytes.length is 20874 while in the Spring Controller it's 35500.

Any idea why that could be?

0 Answers
Related