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

185
Visualizações
How to trigger native browser video download using JS

i want to write a button where user clicked will automatically download a video from a URL.

I have researched on someway, here is my implementation

 const startDownload = (
    url: string | undefined,
    filename = 'Tiktok_livestream.mp4',
  ) => {
    if (!download?.visible || clickedDownloadRef.current || !url) {
      console.log('here', download, clickedDownloadRef.current, url);
      return;
    }
    clickedDownloadRef.current = true;
    fetch(url)
      .then(response => response.blob())
      .then(blob => {
        console.log('finish downloading blob');
        const link = document.createElement('a');
        link.href = URL.createObjectURL(blob);
        link.download = filename;
        link.click();
      })
      .catch(console.error);

    console.log('download');
  };

So the idea is we use fetch to download the data in to blob. Then save it.

The problem of this method is it doesnt have good UX for big files. Because the user only see the downloaded file widget of chrome after the fetch is done ( which take long time for big files). compared to a native video downloading where it will show when user start the download, and user can also see the progress. So i wonder is there any otherway that will trigger the chrome widget right after user click the button, and continously show the progress

The widget im talking about is the native one usually automatically showed when chrome is downloading something enter image description here

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

0

In order to see the download progress natively, the server you are downloading from has to send the Content-Length header in its HTTP response. If you are downloading from a server that doesn't send this header, then your only recourse would be to put up your own relay server that your users send the file request to, and it responds by piping the video file from the true source and attaching the Content-Length header to the HTTP response it sends back to the user.

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