0

I am moving photos from resource/static/images. in spring boot to local drive d:\images

while the photos were in resource/static/images I used the following code to display them in Thymeleaf.

<img th:src="@{/images/one.jpg}">

now I have moved the photos to "d:\images" folder this following code line does not work:

<resources mapping="/resources/**" location="d:/images/three.jpg/" />

the question is, how can I access the photos from local "d:\images" folder?

I am using spring boot with thymeleaf to build a basic web site, to practice the skills I have gained through online courses I have completed. since I am new to creating web site, I am not sure I have any XML file, Spring boot might have created one for me. I was thinking to put the photos in mysql table, but they might make the table heavy to load to web browser. I read somewhere that you can put the photos on the local desk drive such as c: or d: drive. or you put the photos in a folder in server, the problem is have no clue how to do it. here my html:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>sport for all </title>

<a th:href="@{index}">Main Page</a>
</head>
<body>
<div>

<h1></h1>Hi 

<p>
 hello
    hello 
    hello

 </p>
<resources mapping="/resources/**" location="d:/images/three.jpg/" />

</div>

</body>
</html>
codelover
  • 17
  • 6
  • Hi @codelover, your question is unclear as it is currently. Please add more details and more code. E.g. what is that line of XML exactly? – Wim Deblauwe Jun 08 '20 at 11:16

1 Answers1

0

The simplest solution in Spring Boot would be to use the spring.resources.static-locations property:

spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:///D:/images/

Documentation

Tutorial

Similar question on SO

MartinBG
  • 1,500
  • 13
  • 22