I'm uploading files with this method:
@Override
public void store(MultipartFile file, AnimalEntity animalEntity) {
String filename = animalEntity.getNameString() + animalEntity.getAge() + ".jpg";
try (InputStream inputStream = file.getInputStream()) {
Files.copy(inputStream, this.rootLocation.resolve(filename), StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
throw new StorageException("Failed to store file " + filename, e);
}
And showing image with:
<img alt="" src="" th:alt="${dog.id}" th:src="@{${dog.getNameString()} + ${dog.getAge()} + '.jpg'}">
Images are visible only after restarting application. I don't know why and how to solve this problem.
BTW How can i point files instead of using whole path:
private String location = "C:\\Users\\XXX\\Documents\\Projekty\\IntelliJ\\shelter\\src\\main\\resources\\static\\photos";
?