I have a folder named uploads
which is at the same level as src
folder. I upload images to this folder.
Then I added the following configuration to be able to serve the images in thymeleaf:
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/uploads/**")
.addResourceLocations("/resources/","/../../uploads/")
.setCachePeriod(0);
}
}
I try to serve the images in Thymeleaf like this:
<img class="img-thumbnail img-responsive" src="#" th:src="@{'/uploads/' + ${photo}}" alt="">
where ${photo}
is the name file name.
However I get the following error:
The resource path [/../../uploads/rtf_vtvsq1r12q.png] has been normalized to [null] which is not valid.
Apparently the path in my configuration is wrong. Could somebody please tell me what I'm doing wrong?