24

I am trying to open the blob byte streams in the new tab of the browser. It is works, but I am not sure how to set the file name so that each of the documents will have the unique name when downloaded. Now, the document was defaulted to 'document.pdf' when saved.

var blob = new Blob([response.data], { type: "application/pdf" });
            if (blob) {
                var fileURL = window.URL.createObjectURL(blob);
                window.open(fileURL);
            }
Theren
  • 383
  • 1
  • 3
  • 9
  • 1
    Sadly it is not possibe A way to achieve this effect with an IFRAME is shown in [How to prevent blob + guid in browser title](https://stackoverflow.com/questions/24451958/how-to-prevent-blob-guid-in-browser-title) – anx Aug 30 '17 at 02:42
  • 1
    Try with File interface. window.URL.createObjectURL(new File([blob], 'filename.pdf', {type:"application/pdf"})); – jaros May 19 '22 at 09:42

1 Answers1

-7

Give it a filename with the window.open call:

window.open(fileURL, "your filename.extension");

If you are using IE, use navigator.msSaveOrOpenBlob instead:

navigator.msSaveOrOpenBlob(fileURL, "your filename.extension");
Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
Rajeev
  • 381
  • 3
  • 9