0

我正在尝试设置一个 API,它将使用谷歌的照片参考 ID 作为参数从我的谷歌地方 API 返回图像。这是我到目前为止所拥有的:

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);
      }    
    });
};

现在正文没有以正确的格式发送。有没有办法做到这一点而不将其保存为文件然后发送?

4

1 回答 1

1

尝试为服务图像本身设置正确的标题:

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

在您发送请求之前

于 2017-04-04T22:40:43.903 回答