minucha
12/12/2019, 4:13 PM@RequestMapping(value = "/my_image",
method = RequestMethod.GET,
produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getMyImage() throws IOException {
ClassPathResource imgFile = new ClassPathResource("static/images/user/my_image.png");
byte[] bytes = StreamUtils.copyToByteArray(imgFile.getInputStream());
return ResponseEntity
.ok()
.contentType(MediaType.IMAGE_PNG)
.body(bytes);
}
The thing is, I have 7 images, and I believe there has to be a better way than writing this method 7 times. Can someone point me in the right direction? I want generic method for serving images.GarouDan
12/12/2019, 4:15 PMminucha
12/12/2019, 4:19 PM@RequestMapping("/{imageName}"
etc etc and I search for a file, and then if it finds it, then it will return the image, if not I throw exception.
Thanks pal, trying it now đŸ™‚minucha
12/12/2019, 9:44 PMkqr
12/13/2019, 7:22 AMGarouDan
12/13/2019, 12:33 PMminucha
12/14/2019, 5:24 AM