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

588
Visualizações
Convert Buffer (image) to file

I'm looking for the best way to send image files to my server using Apollo Express, and Node. Getting the information there doesn't seem to be an issue, I convert the object into a string but can't find out how to convert it back to a regular file object to store away.

What I have so far;

JS - let buffer = await toBase64(file);

Through Apollo server..

Node - let buffer = Buffer.from(args.image, 'base64');

This gives me a Buffer. I'm unsure how to proceed with NodeJS to convert this back to a file object.

Thanks

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I hope this will be helpfull for you

const file = new File([
      new Blob(["decoded_base64_String"])
    ], "output_file_name");
about 4 years ago · Santiago Trujillo Relatório

0

You can use one of the various write or writeFile methods which accept a Buffer.

const fs = require("fs");

let buffer = Buffer.from(
  "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAGCAIAAABxZ0isAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAQSURBVBhXY/iPAwygxP//AAjcj3EdtT3BAAAAAElFTkSuQmCC",
  "base64"
);

fs.writeFile("pic.png", buffer, (err) => {
  if (err) throw err;
  console.log("The file has been saved!");
});
about 4 years ago · Santiago Trujillo 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