parse wymeleaf переменная Onclick
<button th:onclick="'javascript:upload(' + ${gallery} + ')'"></button>
Shy Sheep
<button th:onclick="'javascript:upload(' + ${gallery} + ')'"></button>