0

I am reeving a large base64 that looks something like this in my Nodejs server. This was sent by converting a PDF to base64 from my front end

data:application/pdf;base64,JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovTWVkaWFCb3ggWzAgMCA1....

Is there a way to save to base64 as a file now using Nodejs?

namko
  • 627
  • 1
  • 14
  • 27

1 Answers1

0

The idea is to decode the base64 string as binary

var bin = Base64.atob(stringToDecode);
// Your code to handle binary data
fs.writeFile('result_binary.pdf', bin, 'binary', error => {
    if (error) {
        throw error;
    } else {
        console.log('binary saved!');
    }
});

referece: Decoding Base64 pdf giving broken file

Arun Kamalanathan
  • 8,107
  • 4
  • 23
  • 39