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.
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.
Update Dec 2024
Since quite some time HTML hyperlinks support the download
attribute that can be used to achieve this; see also this answer to essentially the same question.