title: How to convert the string type from an API response to an image file - ����\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001 -
body: <p>I have used <strong><a href="https://graph.microsoft.com/beta/me/photo/" rel="noreferrer">https://graph.microsoft.com/beta/me/photo/</a>$value</strong> API to get the profile picture of the outlook user. I get an image on running the above API in the rest-client. The content-type of the API is "image/jpg"</p>
  
  <p>But, in Node.js, the response of the API is as follows: </p>
  
  <pre><code>����\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000�\u0000\u0005\u0005\u0005\u0005\u0005\u0005\u0006\u0006\u0006\u0006\b\t\b\t\b\f\u000b\n\n\u000b\f\u0012\r\u000e\r\u000e\r\u0012\u001b\u0011\u0014\u0011\u0011\u0014\u0011\u001b\u0018\u001d\u0018\u0016\u0018\u001d\u0018+"\u001e\u001e"+2*(*2&lt;66&lt;LHLdd�\u
  </code></pre>
  
  <p>I used 'fs' to create an image file. The code is as follows:</p>
  
  <pre><code>const options = {  
      url: "https://graph.microsoft.com/beta/me/photo/$value",
      method: 'GET',
      headers: {
          'Accept': 'application/json',
          'Authorization': `Bearer ${locals.access_token}`,
          'Content-type': 'image/jpg',
      }
  };
  
  request(options, (err, res, body) =&gt; {  
      if(err){
          reject(err);
      }
      console.log(res);
      const fs = require('fs');
      const data = new Buffer(body).toString("base64");
      // const data = new Buffer(body);
      fs.writeFileSync('profile.jpg', data, (err) =&gt; {
          if (err) {
              console.log("There was an error writing the image")
          }
          else {
              console.log("The file is written successfully");
          }
      });
  });
  </code></pre>
  
  <p>The file is written successfully, but the <code>.jpg</code> image file generated is broken. I am unable to open the image.
  The output of the image file is as follows: </p>
  
  <pre><code>77+977+977+977+9ABBKRklGAAEBAAABAAEAAO+/ve
  </code></pre>