title: spring file download using ResponseBody
body: <p>Hello i'm trying create an application allowing me host any kind of file.
  In order to do it i'm exececuting following magic:</p>
  
  <pre><code>@RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET)
      @ResponseBody
      public FileSystemResource 
      getFile(
              @PathVariable("file_name") String fileName) {
          System.out.println(fileName);
          String filePath = "./files/";
          return new FileSystemResource(new File(filePath+fileName)); 
      }
  </code></pre>
  
  <p>But this approach brings three unwanted problems:</p>
  
  <ol>
  <li><p>Some random data is beeing appended to the file</p></li>
  <li><p>The file gets opened in the browser window instead of beeing
          downloaded - i've tried to hack this using something like </p>
  
  <p>produces = "application/octet-stream" </p>
  
  <p>but it only resulted in 406 error.</p></li>
  <li><p>The test.txt is beeing truncated into test, i found a walkaround in providing the app with test.txt/ as fileName but it looks a  bit messy.</p></li>
  </ol>