title: How to show ldapatuh node jpegPhoto?
body: <p>I use ldapauth-fork in node.js to take a user information in ldap but when I try to take a user.jpegPhoto why can't it show this image?</p>
  
  <p>I've tried this:</p>
  
  <pre><code> const jpeg = Buffer.from(user.jpegPhoto, 'binary')
   fs.writeFileSync("foto.jpeg", jpeg);
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>var img64 = Buffer.from(user.jpegPhoto).toString('base64');
  var foto = "&lt;div&gt;&lt;img src='data:image/jpeg;base64,"+img64+"'/&gt;&lt;/div&gt;"
  fs.appendFile('index.html', foto, function (err) {
    if (err) throw err;
       console.log('Saved!');
    });
  </code></pre>
  
  <p>This is all node.js code:</p>
  
  <pre><code>var basicAuth = require('basic-auth');
  var LdapAuth = require('ldapauth-fork');
  var http = require('http');
  var fs = require('fs');
  var qs = require('querystring');
  
  var username = "MOCKUSERNAME";
  var password = "MOCKPASSWORD";
  
  server = http.createServer( function(req, res) {
  
      if (req.method == 'POST') {
          console.log("POST");
          var body = '';
          req.on('data', function (data) {
              body += data;
              //console.log(body);
          });
          req.on('end', function () {
              var data = qs.parse(body);
              var userDecode = Buffer.from(data.username, 'base64').toString('ascii');
              var passDecode = Buffer.from(data.password, 'base64').toString('ascii'); 
  
              res.setHeader('Access-Control-Allow-Origin', '*');
              res.writeHead(200, {'Content-Type':'image/jpeg'});
  
              if (data.username &amp;&amp; data.password) {
  
                  var options = {
                     url:                'XXXXXX',
                     bindDN:             'XXXXX',
                     bindCredentials:    'XXXXX',
                     searchBase:         'XXXXX',
             includeRaw: true,
                     searchFilter:       '(aoldapkey=*' + userDecode + ')'
                     //  reconnect: true
                  }
                  var ldap = new LdapAuth(options);
                  ldap.authenticate(userDecode, passDecode, function(err, user) {
                     if (err) {
                          console.log("login Error: " + err);
                          res.write(JSON.stringify({ success : false, message :     'Authentication failed', serverError: err }));
                              res.end('');
                         } else if(!user.uid) {
                          console.log("user not found Error: " + err);
                          res.write(JSON.stringify({ success : false, message :         
      'Authentication failed, user not found', serverError: err }));
                              res.end();
                         } else if(user.uid) {
                            console.log("success : user "+ user.uid +" found ");
                            var userJsonObject = {
                                success : true,
                                user: {
                                    uid : user.uid,
                                    cn: user.cn,
                                    givenName: user.givenName,
                                    sn: user.sn,
                                    title: user.title,
                                    mobile: user.mobile,
                                    mail: user.mail,
                                    aoJobPosition: user.aoJobPosition,
                                    jpegPhoto: user.jpegPhoto
                                }
                            }
      //------------------------------dont see the image in index.html
                  /*var img64 = Buffer.from(user.jpegPhoto).toString('base64');
                  var foto = "&lt;div&gt;&lt;img src='data:image/jpeg;base64,"+img64+"'/&gt;    
      &lt;/div&gt;"
                  fs.appendFile('index.html', foto, function (err) {
                    if (err) throw err;
                    console.log('Saved!');
                  });*/
      //--------------------------------
                            res.write(JSON.stringify(userJsonObject);
                            res.end();
                         }
                      });
                  } else {
                  res.write(JSON.stringify({ success : false, message : 'You must     
      specify a valid username and password'}));
                      res.end();
                  }
              });
          }
          else {
              var html = fs.readFileSync('index.html');
              res.writeHead(200, {'Content-Type': 'text/html'});
              res.end(html);
          }
      });
      server.on('error', function(err) {
          console.log("Caught server error: ");
          console.log(err.stack);
      });
  
      port = 3000;
      host = '127.0.0.1';
      server.listen(port, host);
      console.log('Listening at http://' + host + ':' + port);
  </code></pre>
  
  <p>This is all node.js code I use ldapauth-fork in node.js to take a user information in ldap but when i try to take a user.jpegPhoto y can´t show this image.</p>
  
  <p>This is index.html :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div&gt;&lt;img src='data:imag/*;base64, 77x73..........3vv70='/&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/IyRbh.png" rel="nofollow noreferrer">index.html</a></p>