Note that there are some explanatory texts on larger screens.

plurals
  1. PODownload lengthy data as a CSV file
    primarykey
    data
    text
    <p>I need to download the contents of a table shown in the view as a CSV file. I have code to format the contents of the table properly so that it can be stored as a .csv file (for example, the column separator is a comma, each record of the table is in a new line). </p> <p>So, in my controller, I have the following code:</p> <pre><code>window.location.href = '/download?data=' + encodeURIComponent($scope.csvString); </code></pre> <p>I am using NodeJs for the server part. Here, I have the following route handler:</p> <pre><code>app.get('/download', function (req, res) { var data = req.query.data; res.attachment('data.csv'); res.setHeader('Content-Type', 'text/csv'); res.end(data); }); </code></pre> <p>This works perfectly fine. The download works and the data in the file downloaded is in perfect CSV format. No issues. </p> <p>The issue arises when there are too many records in the table, that is when the data is huge. Due to this, the query parameter is really huge and I assume that it exceeds the limit and thus, the GET request returns with a 400 (Bad Request) error - note that according to my analysis, the request never reaches the server, instead I observed that the request failed using the Chrome Developer Tools. In the browser, the URL simply is <code>www.my_domain.com/download?data=the_lengthy_data</code>. That's it. The web page is blank / empty and no file is downloaded. </p> <p>Thus, I wish to know how I can download the lengthy data? All examples that I came across do a GET request and thus I have to pass the lengthy data as a query parameter. Is there some other approach?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload