title: Download file served as response
body: <p>I'm trying to achieve the following : On the client side ,using Jquery/Ajax , I make a Post  request to my Django server. On the server side I get this request, extract parameters ,based on that I determine a file path and then I build a HttpResponse , with the intention of having the browser to download that file.</p>
  
  <p>However this doest not happen, although I see in the response the content of the attached file.</p>
  
  <p>The response is build as : </p>
  
  <pre><code> response = HttpResponse(file(path_to_file))
   response['Content-Type'] = 'application/force-download'
   response['Content-Length'] = os.path.getsize(path_to_file)
   response['Content-Disposition'] = 'attachment; filename=\"request.txt\"'
   response['Accept-Ranges'] = 'bytes'
   return response
  </code></pre>
  
  <p>Here's the Response headers as seen with firebug</p>
  
  <pre><code>Accept-Ranges   bytes
  Connection  keep-alive
  Content-Disposition attachment; filename=grequest.txt
  Content-Length  228
  Content-Type    application/force-download
  Date    Fri, 18 Jul 2014 14:55:33 GMT
  Server  nginx/1.4.4
  Set-Cookie  sessionid=41602cd107bbddb41e8884a88c9035c0; Path=/
  Vary    Authorization, Cookie
  </code></pre>
  
  <p>and here's the response content ,seen with firebug</p>
  
  <pre><code>eyJub2RlSUQiOiIwMmI1ODMtYjNhMTljLWM1MjkwYi05YzAwIiwiYWxpYXMiOiJsb2NhbGhvc3QiLCJkbnNOYW1lIjoibG9jYWxob3N0IiwiY2hhc3Npc1NlcmlhbCI6IiIsImFjdGl2YXRpb25zIjpbeyJhY3RpdmF0aW9uSUQiOiI3RjE3LUZFRUQtMTI5Ny1GOTUyIiwicXVhbnRpdHkiOiIzIn1dfQ==
  </code></pre>
  
  <p>In this case the content of the attached file</p>
  
  <p>Any suggestion on what I am doing wrong ?</p>