Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

548
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda