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

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

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