1
votes

I am receiving a PDF as blob from API, I want to open it in new tab giving it a filename I want.

The file is being opened in new tab but the name and link looks like this
Link: "blob:http://localhost:3000/6ff6920c-2737-49cb-9359-e641e4af765d"
Name of PDF: "6ff6920c-2737-49cb-9359-e641e4af765d" This name is different on each open

I am opening new tab with createObjectURL

const fileUrl = URL.createObjectURL(blob)
window.open(fileUrl);

So, I want to change the name of file when it is opened in new tab, instead of having auto-generated one.

1
Are you the end user of this system (with no access to the browser-side code)? Or the front-end developer (with complete control of the receiving JavaScript)? What have you tried so far?Dan H
no, I am generating also the PDF in the APIAlex Alexiuc
I tried to add name/fileName/ filename properties to the blob, tried to convert to FormData, but nothing helped. Also I tried to add "name" parameter to headers from API, that also did not changed nothingAlex Alexiuc

1 Answers

1
votes

Seems this is currently not possible, at least not by embedding the name in a Data URL/URI.

I came across the same question today, did some research, and came to that conclusion. The Media Type part of a data URL/URI (i.e., Strings of the form data:[<media_type>],<data> as defined by RFC 2397) would actually allow additional parameters; e.g., data:application/pdf;name=myPDFfile.pdf;base64,.... Such a parameter doesn't seem to be standardized nor do the most common browsers support it.