0

I am trying to setup an API that will return an image from my google places API using google's photo reference ID as a parameter. This is what I have so far:

module.exports.getPhoto=function(req,res){
    var id=req.params.id;

    var url='https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference='+id+'&key='+process.env.GOOGLEAPI;

    request.get(url, function (err,response,body) {  
      if(err){
        res.status(400).json(err);
      }else{
         res.send(body);
      }    
    });
};

Right now the body is not sending in the correct format. Is there a way to do this with out saving it as a file and then sending it?

1 Answers1

1

Try setting correct headers for serving image itself:

res.set('Content-Type', 'image/gif');

before you send a request

Jakub Pastuszuk
  • 928
  • 4
  • 12
  • 31