Search code examples
imagebase64thymeleaf

Failure to render B64encoded Thymeleaf


I have searched many hours on here and across the Internet an am unable to render a properly B64 encoded image in an object. I have tried every permutation of diacriticals and nothing. Can someone inform the correct

            <tr th:each="re:${reorderList}">
                <td th:text="${re.invoiceNum}"></td>
                <td th:text="${re.ordered}"></td>
                <td th:text="${re.shipped}"></td>
                <td th:text="${re.sku}"></td>
                <td ><img th:src="${'data:image/jpg;base64,'+ re.upc_s" ></td>
                <td th:text="${re.upc01_s}"></td>
                <td th:text="${re.brand}"></td>
                <td th:text="${re.desc}"></td>
                <td th:text="${re.stdCost}"></td>
            </tr>

Solution

  • You're missing the ending curly brace in the th:src attribute of your <img /> tag. The expression should be:

    th:src="${'data:image/jpg;base64,'+ re.upc_s}"
    

    I would personally represent this as:

    <img th:src="|data:image/jpg;base64, ${re.upc_s}|" />