title: Reading png image from request using body-parser and Express
body: <p>I am sending the following request to my server using postman:</p>
  
  <p><a href="https://i.stack.imgur.com/peUB8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/peUB8.png" alt="enter image description here"></a></p>
  
  <p>I try to access the image in my application using the following code:</p>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var express = require('express');
  var bodyParser = require('body-parser');
  
  var indexRouter = require('./routes/index');
  var usersRouter = require('./routes/users');
  
  var app = express();
  
  app.use(bodyParser.raw({
    type: 'image/png',
    limit: '10mb'
  }));
  
  app.use('/', indexRouter);
  app.use('/users', usersRouter);
  
  module.exports = app;
  </code></pre>
  
  <p><strong>index.js (router)</strong></p>
  
  <pre><code>var express = require('express');
  const router = express.Router();
  var Jimp = require('jimp');
  
  /* GET home page. */
  router.get('/', function(req, res) {
    res.render('index', { title: 'Express' });
  });
  
  router.post('/a', function(req, res) {
    var image = req.body;
  
    try{
        Jimp.read(image, (err, input) =&gt; {
          if (err) throw err;
          input.sepia();
  
          input.getBuffer(Jimp.AUTO, (err, output) =&gt; {
            if(err) throw err;
  
            res.writeHead(200, {'Content-Type': 'image/png' });
            return res.end(output, 'binary');
          });
        });
    }catch (err){
        return res.status(400).send(`Error: ${err.message}`).end();
    }
  });
  
  module.exports = router;
  </code></pre>
  
  <p>I was first using a form (with the help of <code>express-fileupload</code> library) to send the image and this worked fine, so I know the problem has to be somewhere before the line <code>var image = req.body</code>. 
  For the Jimp functions (image processing library) to work, the image has to be a buffer representing the png image. 
  When running <code>console.log(image)</code>, the console outputs <code>{}</code>.</p>
  
  <p>Can anybody show me a way to read the png as a buffer when it is sent as a Binary file? </p>