3

I am writing a simple wrapper in node.js which calls Goole Places API and gets a photo using photo_reference. When I run this and process the request from Postman it works but does not display photo itself. In the code below mapsClient.placesPhoto does return a huge response with many tags. Its not just raw image data. My question is how do I extract image or image data from googleResp object and send it back to client?

var googleMapsClient = require('@google/maps').createClient({
  key: 'xyz' 
});

app.post('/getGooglePlacePhoto/:photoref', function(req, res){

    googleMapsClient.placesPhoto({
        photoreference: req.params["photoref"],
        maxwidth: 70,
        maxheight: 70
    }, function(err, googleResp){
        if (!err) {
            debug('got response from google');
            res.set('Content-Type','image/jpeg');
            debug(googleResp.body);
            res.send(200, googleResp.body);
        } else {
                debug(err);
                res.send(409, err);
                return;
        }

    });
});
ReshDev
  • 83
  • 8
  • below is partial response I get when I print entire googleResp object. Does the buffer contain image? and if so how do I access the buffer in node.js IncomingMessage { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [ ], length: 864, – ReshDev Sep 15 '16 at 10:34
  • Yes, the buffer there looks like a JPEG, or at least the start of one, judging from the initial bytes: (ff d8 ff e0). http://stackoverflow.com/questions/6968448/where-is-body-in-a-nodejs-http-get-response might help. – spiv Sep 19 '16 at 03:13

0 Answers0