Я хочу скачать файл с Spring Boot:
@GetMapping("/downloadById.{id}/{fileName}")
@ResponseBody
public ResponseEntity<Object> downloadById(@PathVariable("id") int id, HttpServletResponse response) {
final MultipartFile file = fileUtils.getMultiPartFileById(id, fileName, mimeType);
response.setContentType(mimeType);
response.setContentLength(file.getBytes().length);
response.setHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");
FileCopyUtils.copy(file.getBytes(), response.getOutputStream());
return new ResponseEntity<>(response.toString(), HttpStatus.ACCEPTED);
}
При таком подходе я все время получаю исключение:
org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.lang.String] with preset Content-Type 'application/vnd.oasis.opendocument.text'
, тогда как Content-Type является единственным Я установил.
Установка MimeType в @GetMapping
выходит за рамки, поскольку у меня несколько разных типов файлов. Поэтому я установил его прямо в contentType
. Что работает более или менее (за исключением исключения: - /)
В: Как заставить SpringBoot НЕ использовать конвертер String
и просто обработать ответ с помощью установленного MimeType?