title: How to send a file to browser for downloading?
body: <p>When client request for a file, I use this code to send it:</p>
  
  <pre><code>public static Result download(String file) {
      File file = getRealFile(file);
      return Ok(file);
  }
  </code></pre>
  
  <p>But I found the browser will not download it, but display its content instead. The response header:</p>
  
  <pre><code>Content-Type    text/plain
  Transfer-Encoding   chunked
  </code></pre>
  
  <p>What's the correct way to send a file?</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>Per Razvi's answer, I found an answer seems good for this question: <a href="https://stackoverflow.com/a/1074925/342235">https://stackoverflow.com/a/1074925/342235</a></p>
  
  <p>But do we really have to set so many headers?</p>
  
  <pre><code>header("Cache-Control: public");
  header("Content-Description: File Transfer");
  header("Content-Disposition: attachment; filename=$filepath");
  header("Content-Type: mime/type");
  header("Content-Transfer-Encoding: binary");
  // UPDATE: Add the below line to show file size during download.
  header('Content-Length: ' . filesize($filepath));
  </code></pre>