Хочу картинки отдавать в svg. Но в беке организовал безличную отдачу файлового контента так:
@GetMapping(value = "/{fileName:.+}", produces = APPLICATION_OCTET_STREAM_VALUE)
@ExceptionHandler(value = FileNotFoundException.class)
public @ResponseBody
HttpEntity<byte[]> getFileById(@PathVariable String fileName, final HttpServletResponse response) throws IOException {
StoredFile file = this.storageService.getFileByName(fileName);
if (file == null) {
response.sendError(404, String.format("File %s not found", fileName));
return null;
}
byte[] content;
try {
content = this.storageService.getFileContent(file.getPath());
} catch (IOException e) {
e.printStackTrace();
if (this.userService.isCurrentUserAdmin()) {
response.sendError(404, String.format("File %s (%s) not found", file.getName(), file.getPath()));
} else {
response.sendError(404, String.format("File %s not found", file.getName()));
}
return null;
}
HttpHeaders header = new HttpHeaders();
header.setContentType(APPLICATION_OCTET_STREAM);
header.set("Content-Disposition", "inline; filename=" + file.getName());
header.setContentLength(file.getSize());
return new HttpEntity<byte[]>(content, header);
}
Когда вставляю ссыль на картинку, которую загрузил предварительно, так
<img class="skill-icon" src="/files/123" alt="Postgresql">
то она не показывается в виде картинки от слова совсем.
Если я вставляю содержимое файла svg как html, то все ок.
Как быть? Поможет ли явное указание типа контента при отдаче файла?