Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!