Answers for "show image with sprinboot"

0

show image with sprinboot

@GetMapping("database/{id}")
public ResponseEntity<byte[]> fromDatabaseAsResEntity(@PathVariable("id") Integer id) 
        throws SQLException {

	Optional<PrimeMinisterOfIndia> primeMinisterOfIndia = imageRepository.findById(id);
	byte[] imageBytes = null;
	if (primeMinisterOfIndia.isPresent()) {
	
		imageBytes = primeMinisterOfIndia.get().getPhoto().getBytes(1,
					(int) primeMinisterOfIndia.get().getPhoto().length());
	}
	
	return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(imageBytes);
}
Posted by: Guest on June-09-2020

Code answers related to "show image with sprinboot"

Browse Popular Code Answers by Language