8

I want to open files sent from server on Firefox.

Actually it's working on IE. Here's how I would proceed:

openFile(path, fileName) {
  this.creditPoliciesService
    .openFile(path)
    .toPromise()
    .then(data => {
      var blob = new Blob([data.body], { type: "application/pdf" });
      if (window.navigator && window.navigator.msSaveOrOpenBlob) { //if navigator is IE
        window.navigator.msSaveOrOpenBlob(blob, fileName);
      } else { // Mozilla case
        var fileURL = URL.createObjectURL(blob); //URL.createObjectURL takes only one parameter.
        window.open(fileURL);
      }
    });
}

When I open file I get in new tab a blob adress blob:http://localhost:4200/90907276-947a-47d8-873d-40163 with an empty page

I think I should pass file name but it's not possible with URL.createObjectURL

How can I open files in right format ?

  • in Chrome : files get opened but without a file name at the top bar, I get "XXXXXX" instead.

  • in Firefox : as mentioned I get blob address at the navigation bar with an empty page.

  • in IE : it's working

kelsny
  • 23,009
  • 3
  • 19
  • 48
infodev
  • 4,673
  • 17
  • 65
  • 138

0 Answers0