1

I am trying to download json object as cvs file. This JSON object is actually made out of a Java object that is in the browser itself. I am not firing any network request to get.
It is working fine in Chrome but IE-11 throws below error in Network->Response tab.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>414 Request-URI Too Large</title> 
</head><body> 
<h1>Request-URI Too Large</h1> 
<p>The requested URL's length exceeds the capacity 
limit for this server.<br /> 
</p> 
<hr> 
<address>Omniture DC/2.0.0 Server at *.112.2O7.net Port 80</address> 
</body></html>

In the console , I am getting this.

The code on this page disabled back and forward caching. For more information, see: http://go.microsoft.com/fwlink/?LinkID=291337

My code in javascripts is as below:

  var fileName = "Group Assignment";
        var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
        var link = document.getElementById('download-as-csv');   
        link.href = uri;
        link.download = fileName + ".csv";
        link.innerHTML = 'Download as CSV';
Ahmad
  • 2,110
  • 5
  • 26
  • 36

1 Answers1

1

I'm afraid you can do that in this way. Microsoft Internet Explorer has a limit up to 2048 characters for URIs.

Instead it should be better you serve this CSV from a diferent page and point IE to get from there or use msSaveOrOpenBlob example:

navigator.msSaveOrOpenBlob(new Blob(CSV.split('')), { type: 'text/csv' }), fileName + ".csv");

*works only from IE 10 and above

Community
  • 1
  • 1
Cleiton
  • 17,663
  • 13
  • 46
  • 59
  • Ok, then how do I do that? – Ahmad Apr 25 '16 at 13:29
  • Excellent, So I write this on click event of download-as-csv element? Excuse my naiiveness – Ahmad Apr 25 '16 at 13:46
  • 1
    Just put this: `if(navigator.msSaveOrOpenBlob)link.onclick = function(ev){navigator.msSaveOrOpenBlob(new Blob([new Uint8Array(CSV.split(''))], { type: 'text/csv' }), fileName + ".csv"); ev.preventDefault(); return false;}` below `var link = document.getElementById('download-as-csv'); ` – Cleiton Apr 25 '16 at 13:55
  • Now I can download the file. Thanks.But the problem , it's in binary not plain text. – Ahmad Apr 25 '16 at 14:42
  • 1
    trying change type from "text/csv" to "text/csv;charset=utf-8" – Cleiton Apr 25 '16 at 14:47