Set the file name and open blob pdf type in new tab

Viewed 24958

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);
            }
1 Answers

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");
Related