Я хочу загружать файлы из angular 2. Моя проблема в том, что все файлы, которые я получаю из Spring REST API, имеют двойной размер файла.
Угловой фрагмент:
return this.authHttp.get(this.restAPI + '/downloadFile/' + fileId)
.toPromise()
.then(response => {
// var arrayBufferView = new Uint8Array( response.arrayBuffer() );
// var blob = new Blob( [ arrayBufferView ], { type: response.headers.get("Content-Type") } );
// return blob;
return new Blob([response.arrayBuffer()], { type: response.headers.get("Content-Type")})
})
.catch(this.handleError);
Весенний фрагмент REST:
@RequestMapping(value = "/downloadFile2/{fileId}",
method = RequestMethod.GET)
public void downloadFileHandler2(@RequestHeader("Authorization") String token,
@PathVariable String fileId, HttpServletResponse response) throws IOException {
changeToCustomerDataBase(token);
File file = projectService.readFromDB(fileId);
response.addHeader("Content-Disposition", "attachment; filename="+file.getName());
response.setContentType(Files.probeContentType(file.toPath()));
response.setContentLengthLong(file.length());
FileInputStream fis = new FileInputStream(file);
int c;
while((c = fis.read()) > -1) {
response.getOutputStream().write(c);
}
response.flushBuffer();
fis.close();
}
Файлы, поступающие из базы данных, имеют исходный размер.
Что случилось? Я что-то забыл? Я очень благодарен за любую помощь.