title: Use Axios to get and save an Excel file
body: <p>I am using react and axios to do a POST to a php service that will return a .xlsx file.  The .xlsx file is created properly on the server, but during transit back it gets corrupted, through the Chrome inspector the data seems to be getting converted to a string and many characters are getting changed as a result.  Is there a way to do this?  Things I have tried:</p>
  
  <p>Headers on request</p>
  
  <pre><code>'Accept': 'application/octet-stream',
  'responseType': 'blob',
  </code></pre>
  
  <p>With the response object</p>
  
  <pre><code>fileDownload(new Blob([response.data]), 'report.xlsx');
  </code></pre>
  
  <p>Alternatively with the response object</p>
  
  <pre><code>const url = window.URL.createObjectURL(new Blob([response.data]));
  const link = document.createElement('a');
  link.href = url;
  link.setAttribute('download', 'file.xlsx');
  link.click();
  </code></pre>
  
  <p>No matter what I try it seems to be getting corrupted.  On the server side I have the following PHP code: </p>
  
  <pre><code>$response = new Stream();
  $response-&gt;setStream(fopen($tempFilePath, 'r'));
  $response-&gt;setStatusCode(200);
  $response-&gt;setStreamName($tempFilePath);
  $responseHeaders = new Headers();
  $responseHeaders-&gt;addHeaders(array(
      'Content-Disposition' =&gt; 'attachment; filename='report.xlsx',
      'Content-Type' =&gt; 'application/octet-stream',
      'Content-Length' =&gt; filesize($tempFilePath),
      'Expires' =&gt; '@0', 
      'Cache-Control' =&gt; 'must-revalidate',
      'Pragma' =&gt; 'public'
  ));
  $response-&gt;setHeaders($responseHeaders);
  return $response;
  </code></pre>