0

I'm trying to convert blob that I receive it as a buffer to pdf,

           exports.findAll = (req, res) => {
           leave.findAll({where:{Reponse:null} , attributes:['Document']})
          .then(leave => {

           console.log(leave[0].Document);
            // outPut 
             //  <Buffer 5b 6f 62 6a 65 63 74 20 4f 62 6a 65 63 74 5d>
           var buffer = new Buffer.from(leave[0].Document);

          console.log(buffer.toString('utf8'));
           //[object Object]


         });

the leave[0].Document is a blob file from my database

Riahi Rahma
  • 3
  • 2
  • 5
  • What are you trying to do with that blob? If you want to pass it as pdf to a browser take a look at this question https://stackoverflow.com/questions/43098071/how-to-output-a-pdf-buffer-to-browser-using-nodejs – vitkarpov May 16 '20 at 04:57
  • I want to send it to my react app as a download link, I took a look but didn't help – Riahi Rahma May 16 '20 at 05:30
  • I'm curious why you're storing static data (such as pdf) in the database, not in s3 but it's okay, I guess. Make sure you're sending the right Content-Type header, the blob should be in the response's body, I guess. Details: https://stackoverflow.com/questions/6293893/how-do-i-force-files-to-open-in-the-browser-instead-of-downloading-pdf – vitkarpov May 16 '20 at 06:49
  • I'm storing a user input which includes an attachment file, that's why I have a pdf file in my database – Riahi Rahma May 16 '20 at 06:56
  • makes sense! Try to take a look at the appropriate headers. – vitkarpov May 16 '20 at 07:06

0 Answers0