'Spring boot don't upload data to database untill image loaded to server
I am creating an admin panel for a website using spring boot and thymeleaf. An admin can add new product from the panel and also add the product's images. But usually uploading several images from client takes sometime. So when admin clicks upload button, i want first images fully uploaded to server and then all the data is added to database and admin redirected to main page. Is there anyway of doing that? Waiting for images to be completely uploaded to the server and then shown in the main page or else the data shows up without an image
var images = new ArrayList<Image>();
for (var image : model.getImages()) {
Path path = Path.of("/img/" + image.getOriginalFilename());
images.add(new Image("img/" + image.getOriginalFilename(), shoe));
try {
Files.copy(
image.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
imageService.saveAll(images);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
