2

I would like to do a file (of any kind) download using IE9 without any redirection. By redirection I mean providing a URL of the resource I am trying to download to the current document forcing a download if the MIME type is not a document type.


So I am left with getting the data using the XHR object and find a way to save it on disk. Since I am using IE9, I can't use any File API provided in IE10+.

So forget about:


Right now I am getting the data after the REST call and trying to write it into a document like in this post: Javascript Save CSV file in IE 8/IE 9 without using window.open()

But, the problem is document.write() seems to encode anything written to it in UCS-2, so binaries sent from the back-end are reinterpreted and the file gets corrupted. I am guessing that only text-based files could be saved then.

Last and not the least, I SHOULD not use flash.

Does anyone have an idea in mind to resolve the encoding issue or another technique to do the download?

If it can help, I am using angularjs as a front-end JS framework

Community
  • 1
  • 1
gmolaire
  • 1,091
  • 10
  • 19
  • If you're not worried about file name preservation, get a binary safe _Base64_ library and create a data uri with mime `application/octet-stream`. Although why you don't just serve it as octet-stream is the real question – Paul S. Aug 05 '15 at 15:41
  • How do you tell the document that it should expect binaries input and not text? If your solution doesn't involve writing to the document, how do you save that data on disk then? – gmolaire Aug 05 '15 at 15:49

1 Answers1

1

For the limitation we had, passing the token as a parameter to get the file downloadable resource was the solution. When we uplift IE, we shall change the solution tough.

It implies removing any security chain filter and do a manual validation on the token in the backend.

gmolaire
  • 1,091
  • 10
  • 19