1

I have a javascript file that requests for data from server.The data has to be displayed in CSV format. The data size can reach huge limits. The following is the code I am using in javascript to download the file.

var tmp = document.createElement('a');        
var csvData = new Blob([dataString], { type: 'text/csv' }); 
var csvUrl = URL.createObjectURL(csvData);
tmp.href =  csvUrl;     
tmp.setAttribute('download', "abc.csv");
tmp.click();

The file size if it reaches 50MB crashes the chrome. The chrome gives "aw snap" error. But I should be able to download data more than 1GB. How to download such huge CSV file without crashing chrome browser.

cweiske
  • 28,704
  • 13
  • 124
  • 186
Mumzee
  • 589
  • 1
  • 8
  • 23
  • You don't display or download 1Gb of data in browser. Basic solution would be to implement pagination and corresponding API to fetch only portions you need. – Klaster_1 Mar 27 '15 at 15:05
  • Why not? I want to save the data which is in the server in client machine in CSV format. – Mumzee Mar 28 '15 at 05:52

1 Answers1

2

The approach of converting data to string and triggering click event was totally wrong. What really is required is to stream the file. The below link explains how to stream a file from HttpServlet's response object.

Streaming large files in a java servlet

Community
  • 1
  • 1
Mumzee
  • 589
  • 1
  • 8
  • 23