Я не могу понять, как загрузить файл из API с помощью Angular.Я отправляю BLOB-объект из бэкэнда, но не думаю, что преобразовал его правильно, так как он дает мне ошибку сериализации.Тем не менее, bytearray дает мне его содержимое, но не в виде загрузки.
Это мой код Java:
@GetMapping("{id}")
public byte[] getExambyId(@PathVariable int id) {
Exam exam = new Exam();
byte[] file;
try {
exam = examRepository.findById(id).get();
file = IOUtils.toByteArray(new FileInputStream(storageService.load(exam.getSkelet()).toFile()));
} catch (NoSuchElementException e) {
log.error("Exam with id: " + id + " not found.", this.getClass());
return null;
} catch (StorageFileNotFoundException e) {
log.error("Cannot find examfile: " + exam.getSkelet() + ".", this.getClass());
return null;
} catch (FileNotFoundException e) {
log.error("Cannot find file with filestream: " + exam.getSkelet() + ".", this.getClass());
return null;
} catch (IOException e) {
log.error("IoException on: " + exam.getSkelet() + ".", this.getClass());
return null;
}
return file;
}
Это мой сервис в веб-интерфейсе:
getExamSkeletById(id) {
window.open(APIURL + '/' + id);
}