Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i am trying to hit an API to read the file its giving me in input stream response, i need to convert that response either as a json object or into a file(xlsx) format.

Below is the code for calling the API,

var options = {
         host: 'xxxxxxx.xxxxx.com',
         port: xxxx,
         path: '/xxxxx/api/downloadFile?code=' + req.query.code,
        method: 'GET',
        headers:{ 
            'user_id': req.headers.user_id,
            'access_token': req.headers.access_token 
         }
      };
      var req = https.request(options, function (res) {
        var decoder = new StringDecoder('utf8');
        res.on('data', function(chunk) {
            console.log(chunk)
            var textChunk = decoder.write(chunk);
            console.log(textChunk)
        });
      });
      req.end();
      req.on('error', function(e) {
        console.error(e);
    });


What I have tried:

Tried to convert the response in buffer format and write into a file---but didnt work
As well tried to directly read the file from the API
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900