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

212
Visualizações
How to make a pdf from MongoBD Binary with File API?

I would like some help to make a File object from a pdf stored in MongoDB. I am not using GridFS, the file is stored as such: File structure in MongoDB

I am using this function to make the File:

const handlegetfile = () => {
    API.getFile(2).then((result) => {
      console.log(result.data);
      const file = new File(Uint8Array.from(result.data.File.data), result.data.File.name);
      console.log(file);
      API.writeFile({
        CodeTiers: "2525",
        Type: { value: "non", label: "testfile" },
        Format: "pdf",
        File: file,
      });
    });
  };

The .pdf file created by the writeFile() function can't be opened, and when opened with an editor, it looks like this: pdf data after retrieved

Important: I do not want to write the file to the disk, writeFile() is just here to be sure that the pdf can be opened.

The thing is: the data goes from this in the original file: original pdf data

To this in MongoDB: data in MongoDB

To what is in the second screenshot. I am pretty sure the problem comes from the cast to a Uint8array but I can't find what else to use there for it to work. I tried exploding the response with {...result.data.File} and using an ArrayBuffer, also by simply casting to an array new File([result.data.File.data], result.data.File.name) but I couldn't get it to work either way.

Could you help me please ?

about 4 years ago · Juan Pablo Isaza
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