title: Creating a file download link using Spring Boot and Thymeleaf
body: <p>This might sound like a trivial question, but after hours of searching I am yet to find an answer to this. The problem, as far as I understand, is that I am trying to return a <code>FileSystemResource</code> from the controller and Thymeleaf expects me to supply a <code>String</code> resource using which it will render the next page. But since I am returning a <code>FileSystemResource</code>, I get the following error:</p>
  
  <pre><code>org.thymeleaf.exceptions.TemplateInputException: Error resolving template "products/download", template might not exist or might not be accessible by any of the configured Template Resolvers
  </code></pre>
  
  <p>The controller mapping I have used is:</p>
  
  <pre><code>@RequestMapping(value="/products/download", method=RequestMethod.GET)
  public FileSystemResource downloadFile(@Param(value="id") Long id) {
      Product product = productRepo.findOne(id);
      return new FileSystemResource(new File(product.getFileUrl()));
  }
  </code></pre>
  
  <p>My HTML link looks something like this:</p>
  
  <pre><code>&lt;a th:href="${'products/download?id=' + product.id}"&gt;&lt;span th:text="${product.name}"&gt;&lt;/span&gt;&lt;/a&gt;
  </code></pre>
  
  <p>I don't want to be redirected anywhere, I just need the file downloaded once the link is clicked. Is this actually the right implementation? I'm not sure.</p>