jeudi 14 décembre 2017

How to download a xls file from Rails route?

In my AngularJS application, I'm calling a route (from a Rails application) that returns me the contents of a xls file (like below):

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:html="http://ift.tt/qQdaDR">
  <Worksheet ss:Name="Sheet1">
    <Table>
      <Row>
        <Cell><Data ss:Type="String">Ecpm</Data></Cell>
        <Cell><Data ss:Type="String">Total Revenue</Data></Cell>
      </Row>
      .
      .
      .
      <Row>
        <Cell><Data ss:Type="String">4.9</Data></Cell>
        <Cell><Data ss:Type="String">1587.25</Data></Cell>
      </Row>
    </Table>
  </Worksheet>
</Workbook>

The URL is like /api/statistics/earnings/medias_served_export/20171001/20171030.xls

How can I download the file instead of just receive all the text? Should the backend set extra Headers in the route's method?

Aucun commentaire:

Enregistrer un commentaire