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

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