Issue
@RequestMapping( value= "/get/{imageName}",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE ,method = RequestMethod.GET)
public ResponseEntity<byte[]> getImage1(@PathVariable("imageName") String imageName) throws IOException {
final Optional<ImageModel> retrievedImage = imageModelRepository.findByName(imageName);
ImageModel img = new ImageModel(retrievedImage.get().getName(), retrievedImage.get().getType(),retrievedImage.get().getPicByte());
byte[] imageArray= retrievedImage.get().getPicByte();
return ResponseEntity.ok().body(imageArray);
}
Solution
Content-Type
of application/octet-stream
forces it to always download.
You can try something like follows:
...
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("image/jpeg"));
...
headers.add("Content-Disposition", "inline; filename=" + fileName);
...
ResponseEntity<byte[]> returnValue = new ResponseEntity<>(imageArray, headers, HttpStatus.OK);
return returnValue;
Answered By - Mo_-
Answer Checked By - Marie Seifert (JavaFixing Admin)