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.

2
  • 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. Commented Mar 27, 2015 at 15:05
  • Why not? I want to save the data which is in the server in client machine in CSV format. Commented Mar 28, 2015 at 5:52

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.