Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
javascript - download a file in client's browser, then actually download the file instantly

What I actually want is to make something like Mega web, where when you download a file, first it downloads it inside your browser, then your browser prompts to actually download the file and the file will be downloaded instantly.

So far this is what I've found as a solution:

fetch(url).then(response => response.text())
  .then(uri => {
    var link = document.createElement("a");
    link.download = name;
    link.href = uri;
    link.click();
  })

while it works for small pictures, I've tried this approach on a 80mb file, and the tab crashed.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I haven't tested this yet but apparently this is working:

fetch(url)
  .then((response) => response.blob())
  .then((blob) => {
    var URL = window.URL || window.webkitURL;

    var fileURL = URL.createObjectURL(blob);

    var link = document.createElement("a");
    link.download = name;
    link.href = fileURL;
    link.click();

    URL.revokeObjectURL(fileURL);
  });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda