You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow createObjectURL to retain filename from File (and similar) objects #203
We have a datastore that requires authentication to retrieve files (e.g. PDF, CSV, ZIP, PNG, or some Office suite file format) -- it has a file name, a content type, and data. We'd like to allow users to click a link (or button/...) and have the "file" corresponding to that data (which we currently retrieve in a Blob) open in their browser (or download depending on how the browser is feeling) and if at some point the browser decides to save the file (e.g. because the user asks to save a file, or because it doesn't have an internal handler) then we'd like it to favor our proposed filename instead of a blob id.
What solutions exist today?
We can construct a Blob or a File w/ a Blob and call createObjectURL with it.
We can create an anchor a with a#download with the href set the the url from createObjectURL such that users can click the anchor to get our suggested filename.
We can add an iframe containing our blob url
Fwiw, Microsoft had an msSaveBlob which included a defaultName field...
How would you solve it?
Change the specification for createObjectURL so that for objects that have a name (e.g. File), browsers should prefer that name over the blob when saving.
Might be noted that Firefox is already able to derive this name in the case of an empty <a download> attribute, so the blob URL entry as currently specified might be enough to derive that name.
I'm not quite sure where it's specified where to get the file name for downloading a resource opened as a "document" though, and this Firefox fails it too.
I guess ideally Fetch would generate the appropriate headers so HTML doesn't have to know it's downloading a Blob object, but perhaps that should only happen for the download code path as people might rely on the headers a Blob object has today.
Activity
Kaiido commentedon Nov 1, 2024
Might be noted that Firefox is already able to derive this name in the case of an empty
<a download>attribute, so the blob URL entry as currently specified might be enough to derive that name.I'm not quite sure where it's specified where to get the file name for downloading a resource opened as a "document" though, and this Firefox fails it too.
annevk commentedon Nov 4, 2024
I guess ideally Fetch would generate the appropriate headers so HTML doesn't have to know it's downloading a
Blobobject, but perhaps that should only happen for the download code path as people might rely on the headers aBlobobject has today.But yeah, this should just work.
mkruisselbrink commentedon Nov 6, 2024
I believe this is the same issue as whatwg/html#4362?
jsoref commentedon Nov 7, 2024
I was told in whatwg/html#10735 (comment) to file it here, so I did... 😵💫
lili2012 commentedon Feb 14, 2025
stackoverflow has relevant question and not any good solution
https://stackoverflow.com/questions/44061354/set-the-default-save-as-name-for-a-an-embed-or-iframe-that-uses-a-blob
https://stackoverflow.com/questions/53548182/can-i-set-the-filename-of-a-pdf-object-displayed-in-chrome
DorianNaaji commentedon Jul 28, 2025
q2p commentedon Jul 28, 2026