Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

435
Views
JavaScript "new Blob" - can you rename the blob's ID?

I have a function that successfully downloads a blob as text; however, its label (or ID, not exactly sure) appears as "blob:file:///*". Is there a way to rename this? blob:file:///

Here's my script:

function download_as_txt(options) {
    let file = new Blob([options.data.toString()], { type: options.type }),
    url = URL.createObjectURL(file),
    a = document.createElement("a")
    ;
    a.href = URL.createObjectURL(file);
    a.download = options.name;
    document.body.appendChild(a);
    
    a.click();

    document.body.removeChild(a);
    window.URL.revokeObjectURL(url);
};

download_as_txt({
    name: `${pages[active_page]["label"]} Export - ${current_epoch}.txt`,
    data: config,
    type: "text",
});

Here's what I've looked into:
• new Blob - option properties appear to allow 'type' and 'endings'
• new File - let file = new File([options.data.toString()], 'test.txt', { type: options.type }), // same as blob, and 'test.txt' doesn't appear anywhere
• troubleshooting - console.log(a) // looks like the name is tied to the 'href' attribute, so it looks like my current "temporary url" method may not work

In the meantime I'll look into using something like fs, but I'd still like to open an explorer window so my users can choose their download directory without needing to fill out a form. ...maybe have them select a directory, download to it, and alert when finished.

Edit:
I made a workaround for Electron:
• dialog.showOpenDialog
• fs.writeFile
• alertify.alert
The code doesn't look as clean as downloading a new blob, but at least I'm not manipulating the DOM (beyond alertify, anyway)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!