Include html file uploaded by user

130 views Asked by At

This it what I would like to do: A user uploads a bunch of html files as a zip archive. I unzip that archive and display the html content on the website.

For that, I would like to include the html content into a thymeleaf page. I have tried this so far:

<div th:include="http://localhost:8181/MySpringApp/uploads/include.html"></div>
<div th:include="@{/uploads/include.html}"></div>
<div th:include="@{~/uploads/include.html}"></div>

In all three cases I get the following error (with varying URL):

Exception processing template "dashboard": Error resolving template "/uploads/include.html", template might not exist or might not be accessible by any of the configured Template Resolvers (dashboard:40)

How would I get this to work? I have only seen examples of including static files from the template folder. But that's not what I would like to do.

I am using Wildfly 9 and in the standalone/data folder I have created the uploads folder.

3

There are 3 answers

0
Ihor Dobrovolskyi On

The code like this should work:

<div th:include="@{/uploads/include}"></div>
0
avilac On

Could it be a permisson issue? I'm just wondering because you say that some external user can uploads those files, so you might not have the right permisson to display or use them.

Hope it helps!

0
DimaSan On

Assuming that your uploads folder is under templates, insert the HTML as:

<div th:insert="~{uploads/include}"></div>

Btw, th:include is not recommended since Thymeleaf 3.0.