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

547
Visualizações
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 Respostas
Responde à pergunta

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