0

I have been trying to Send large csv type file in HTTP response. I tried using the following

p_response.setHeader("Content-Disposition", "attachment; filename=" + URL.encodeURLFragment(x_filename) + ";");
p_response.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

This exports the excel files with small data easily. But when I tried exporting a bigger csv file, instead of downloading the file in csv(comma separated) format, it just dumped the entire data into the web page.

In the Response Headers (in the network tab in chrome), I can see that it does not show the Content-Disposition, Content-Type or the Content-length when sending a large CSV file. It also has Transfer-Encoding: chunked in the Response Headers (Which is not observed when a csv file with less data is downloaded).

Can anyone please help?

Phoenix
  • 33
  • 1
  • 1
  • 5

1 Answers1

0

You can solve using blob

csvData = new Blob([csvString], { type: 'text/csv' }); 
var csvUrl = URL.createObjectURL(csvData);
a.href =  csvUrl;

References:

Export HTML table to csv in google chrome browser