2017-04-04 76 views
0

我想设置一个API,它将使用谷歌的照片引用ID作为参数从我的谷歌地方API中返回一个图像。这是我到目前为止:从Node.js中的http请求发送图像文件

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

现在身体没有以正确的格式发送。有没有办法做到这一点,把它保存为一个文件,然后发送它?

+0

什么是错的格式之前? – user3094755

+0

它返回img,就像我在文本编辑器中读取图像 –

回答

0

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

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

你发送一个请求