Home:ALL Converter>Extract binary data (file) that was sebt from postman in nodejs/expressjs

Extract binary data (file) that was sebt from postman in nodejs/expressjs

Ask Time:2018-06-08T21:59:26         Author:Uriel Parienti

Json Formatter

I am trying to test file uploading in my back-end. Currently using postman to send a binary data in the body, which is a file, and I'm trying to extract the data from the post request.

req.body 

returns:

<Buffer 50 4b 03 04 14 00 06 00 08 00 00 00 21 00 7c 6c 98 16 69 01 00 00 a0 05 00 00 13 00 08 02 5b 43 6f 6e 74 65 6e 74 5f 54 79 70 65 73 5d 2e 78 6d 6c 20 ... >

How can I treat the buffer as file content? It should replace this function:

   fs.readFile('./text.txt',  function (err, contents) {
                if (err) {
                     console.log('Error: ', err);
                }
                    uploadFile(contents,cb);
            });
          } ;

can I get the same info (same as contents) from the buffer abd pass it on to

uploadFile(contents,cb);

(When the front-end wil be created it will be a form data but for now I am only want to build it for testing.)

Author:Uriel Parienti,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762325/extract-binary-data-file-that-was-sebt-from-postman-in-nodejs-expressjs
yy