How to return file (byte array) from spring controllers
Sep 6, 2018 · 1 min read
Here comes an example how one can retrieve file (byte array) from the spring controller using ResponseEntity of byte[]
@GetMapping(value = "/{id}")
public ResponseEntity<byte[]> get(@PathVariable UUID id) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
return new ResponseEntity<>(service.get(id), headers, HttpStatus.OK);
}