I have problems downloading files in a Spring4 application.
TL; DR
After downloading the .xlsx file, we have more of the file than the original. In addition, we cannot open it in Microsoft Office.
Problem
I checked every tutorial, made an implementation in each case. It also works with almost all types of files except XLSX.
Scenario
I am using a file (e.g. http://www.sample-videos.com/download-sample-xls.php first )
In terminal:
$ ls -la | grep .xlsx
-rw-r--r--@ 1 user staff 19K 31 mar 13:46 SampleXLSFile_19kb.xlsx
19Kb
But after loading I have:
$ ls -la | grep .xlsx
-rw-r--r-- 1 user staff 24K 31 mar 13:47 SampleXLSFile_19kb.xlsx
whaaat !? 24K?
After debugging, I got to the point that the file is in the Jboss temp directory with a new large size.
What is the problem?
I cannot open the .xslx file in excel after loading, I cannot process them in the application. The file is damaged.
?
, xlsx .
:
@RequestMapping(value = "/api/file", method = RequestMethod.POST)
public ResponseEntity upload(@RequestParam("file") MultipartFile file) throws Exception {
if (!file.isEmpty()) {
try {
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(new File(this.uploadDirectory + "/" + file.getOriginalFilename())));
FileCopyUtils.copy(file.getInputStream(), stream);
stream.close();
} catch (Exception e) {
throw new Exception(e);
}
}
return new ResponseEntity(null, HttpStatus.OK);
}
- .
@UPDATE
, .xslx. .
, org/apache/commons/fileupload/MultipartStream.java . , .
, 43M zip , zip 78M.
@SOLVED
, . spring, . , .