Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

427
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda