title: AngularJS CSV File Download from API
body: <p>I have an admin control panel where admin users can set a few options and then click a button to run a report. The report should return a CSV file download prompt to the user.</p>
  
  <p>I am using <code>ui-router</code> and <code>$resource</code> services. The response headers/mime type are set correctly, but the CSV file is returned as text (no file download initiated) by the <code>$resource</code> handler.</p>
  
  <p>I tried creating the download link directly, by forming a querystring from the <code>$scope</code>, but unfortunately my API's authentication scheme uses a custom HTTP header token and it's not possible to send that to the API (which is also on another subdomain) via an anchor tag, such as this one:</p>
  
  <pre><code>&lt;a href="http://example.com/admin/report/csv?usertype=1&amp;days=5"&gt;Run&lt;/a&gt;
  </code></pre>
  
  <p>Is there a way to initiate a file download prompt using an XHR request (with custom header)?</p>