0

I am trying to open a blob with file type PDF in IE the name of the blob is working and downloading as well.

But for Chrome and Firefox i am opening it up in a new tab and the name in the new tab comes exactly the same of blob name.

I want to change the file name but didn't found any way of doing that.

Below is the code i am trying with.

    this.downloadReport().subscribe(
  data => {
    var blob = new Blob([data], { type: 'application/pdf' });
    var newWindow = window;
    if (newWindow.navigator && newWindow.navigator.msSaveOrOpenBlob) {
      var fileData = [data];
      var blobObject = new Blob(fileData);
      window.navigator.msSaveOrOpenBlob(blobObject, filename);
      self.alertService.stopLoadingMessage();
    } else {
      var objectUrl = URL.createObjectURL(blob);
      setTimeout(function () {
        var newWindow = window.open(objectUrl);
        setTimeout(function () {
          newWindow.focus();
          newWindow.print();
          self.alertService.stopLoadingMessage();
        }, 1000);
      }, 2000);
    }
  },
  err => {
    this.alertService.showStickyMessage('Problem while downloading the file.');
    console.error(err);
  }
);
Ancient
  • 3,007
  • 14
  • 55
  • 104
  • check this link once https://stackoverflow.com/questions/41947735/custom-name-for-blob-url – Mr code. May 06 '19 at 12:56
  • Well, i did browse many of such threads but there have to be some work around for this and unfortunately the example given in above thread isn't working anymore. I am still exploring – Ancient May 06 '19 at 13:04

0 Answers0