title: Node: Express: How to handle application/octet-stream;charset=;UTF-8 response?
body: <p>I have a node-express application.
  There, I'm trying to make a call to an API which is responding an raw xlsx object as </p>
  
  <blockquote>
    <p>'Content-Type' : 'application/octet-stream;charset=;UTF-8'</p>
  </blockquote>
  
  <p>Code how I'm calling the API:</p>
  
  <pre><code>var unirest = require("unirest");
  
  var reqClient = unirest("POST", "https://api.application.com/getExcel");
  reqClient.headers({ "Authorization": "Bearer " + req.session.passport.user.token, 
  "content-type": req.headers['content-type'], "application/json"});
  reqClient.type("json");
  reqClient.send(JSON.stringify(requestbody));
  reqClient.end(function(res) {
  if (res.error) throw new Error(res.error);
  console.log(res.body);
  });
  </code></pre>
  
  <p>Now 2 things I'm trying to do actually with this data.</p>
  
  <ol>
  <li>Write that into an excel file.
  Below is the code how I'm trying it:</li>
  </ol>
  
  <pre><code>    let data = res.body // res is the response coming from the API
      let buf = Buffer.from(data);
      excelfile = fs.createWriteStream("result.xlsx");
      excelfile.write(buf);
      excelfile.end();
  </code></pre>
  
  <ol start="2">
  <li>Trying to send it to <strong>UI</strong> where the excelfile will get created.
  Below is my code for that:</li>
  </ol>
  
  <pre><code>    let data = res.body // res is the response coming from the API
      let buf = Buffer.from(data);
      response.write(buf); //response is the response to the request to ui
      response.end();
  </code></pre>
  
  <p>So in both the cases the file is coming corrupted. </p>
  
  <p>But the API response is prefect because, when it's directly getting consumed by the <strong>UI</strong>, xlsx file is generating properly.</p>