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

543
Views
How to download PDF from big base64 string with JavaScript and Blazor?

In Blazor WASM I have this code:

protected async Task Download()
    {
        base64Data = await Http.GetByteArrayAsync(url);
        await jsRunTime.InvokeVoidAsync("downloadFile", "application/pdf", base64Data, "test.pdf");
    }

And in the JavaScript file I have this:

function downloadFile(contentType, base64Data, fileName) {
    const linkSource = `data:${contentType};base64,${base64Data}`;
    const downloadLink = document.createElement("a");
    downloadLink.href = linkSource;
    downloadLink.download = fileName;
    downloadLink.click();
}

If I try to get a really small pdf it works, but if the base64 string is too large (a file with over 400kB), I have a network failure when downloading the file. A strange thing is on Edge network tab, at Fetch/XHR, don't matter the file I try to download, the size is always 576kB.

Any idea of what to do? Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I finally made it work.

I had to use GetStringAsync and Trim the server response because the base64 string was surrounded by quotation marks.

protected async Task Download()
{
base64Data = await Http.GetStringAsync(url);         
base64Data = base64Data.Trim('"');
await jsRunTime.InvokeVoidAsync("downloadFile", "application/pdf", base64Data, "test.pdf");
}

Thanks guys!

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!