2

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
  • 30,033
  • 14
  • 133
  • 194
Mumzee
  • 719
  • 1
  • 11
  • 25

2 Answers2

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
  • 719
  • 1
  • 11
  • 25
0

Alternative solution authored by Eli Grey, eligrey.com is to convert to blob and use URL.createObjectURL(blob)

dank8
  • 361
  • 4
  • 20