I wanted to convert blob images stored in database into jpeg files and then download them as zip file.
Here is the implementation so far.
public void downloadImages(HttpServletResponse response) throws IOException {
List<ScreenUserEntity> users = screenUserRepository.findAll()
.stream().filter( user -> user.getImage() != null && user.getImage().length > 0).collect(Collectors.toList());
String filename = "Image.jpeg";
response.setContentType("image/jpeg");
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"");
byte[] decodedBytes = users.get(0).getImage();
ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
BufferedImage image = ImageIO.read(bis);
File outputFile = new File("output.png");
ImageIO.write(image, "png", outputFile);
}
Is there a way to add a file/ image / zip file into the response?
Thanks for your help/