Search code examples
javascripthtmlspring-bootfile-uploadthymeleaf

Is there simple way to display uploaded files as pdf, xml, .xlsx in spring boot-thymeleaf


I uploaded files in static resources and I'm displaying them on the page like I would display any picture.

<div th:each="tempFile:${files}" class="col-2 mb-4">
     <a th:href="@{'/user/file/' + ${tempFile.idFile}}">
         <img th:src="@{'/files/'+${tempFile.fileName}}" alt="img">
     </a>
</div>

But I don't know how to display files that are not images. I would like to display an icon at least if the file isn't an image (pdf icon for pdf extension). I suppose it is possible with JavaScript but I'm just starting to learn him.

I would appreciate any help.

enter image description here


Solution

  • After a bit of brainstorming, I decided to use the strings.endsWith method in the conditions and put file extension as a suffix.