title: Grails File Download
body: <p>I'm trying to craete a site which allows users to upload any file type they like. I've implemented this feature fine, and the file is held on the server. Later on they can download the file to view, but i'm having trouble getting it to work.
  <br/><br/>
  I've used any examples I can get hold of but they all tend to use text files as examples. My problem is that pdf's and many other file types aren't downloading properly. They seem to download fine, but none of the files will open successfully. Comparing the files, it seems most of the files content is correct, but certain parts are not.
  <br/><br/>Here's my groovy code:</p>
  
  <pre><code>def file = new File(params.fileDir)    
  response.setContentType("application/octet-stream")
  response.setHeader("Content-disposition", "filename=${file.getName()}")
  response.outputStream &lt;&lt; file.text
  return
  </code></pre>
  
  <p>This code is held inside a controller which is called by a download link.
  I've tried playing around with different contentTypes, but I don't know which I could use for any type - is there one? Anything I try doesn't solve the problem.</p>
  
  <p>Thanks for your help.</p>