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

109
Visualizações
Reverse FileReader - Reassamble file from string

I get the file to a string:

const r = new FileReader()
r.readAsText(file, 'UTF-8')
r.onload = (evt) => {
     this.file = evt.target.result
};

After upload a Zip, Text or Image file my string looks like: data:text/plain;base64,VTJGc.....

How can i reverse the readAsText and get a downloadable file?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The "string" you got is a Base64 URL (which you can copy and paste into a new browser tab and view the contents), and it actually simplified downloading the file, so please don't reverse the process.

One way is to create a link element in your HTML and click on it:
The example won't work because it's in an embed that has limited permissions.

function download(b64, name) {
  const a = document.createElement("a");
  a.href = b64;
  a.download = name;
  document.body.appendChild(a);
  a.click();
}

download("data:text;base64,SGVsbG8sIHdvcmxkIQ==", "helloworld.txt");

If you really want to reverse the process, you can easily decode Base64 with atob():

const decode = str =>
  atob(str.replace(/^data:\w+;base64,/, "")); // remove `data:text;base64,`


console.log(decode("data:text;base64,SGVsbG8sIHdvcmxkIQ=="));

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