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

183
Views
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 answers
Answer question

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 Report
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!