在 Node.js 中从 http 请求发送图像文件
Sending image file from http request in Node.js
我正在尝试设置一个 API,它将 return 来自我的 google 地点 API 的图像,使用 google 的照片参考 ID 作为一个参数。这是我目前所拥有的:
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);
}
});
};
目前发送的正文格式不正确。有没有一种方法可以不将其保存为文件然后发送?
尝试为服务图像本身设置正确的headers:
res.set('Content-Type', 'image/gif');
发送请求之前
我正在尝试设置一个 API,它将 return 来自我的 google 地点 API 的图像,使用 google 的照片参考 ID 作为一个参数。这是我目前所拥有的:
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);
}
});
};
目前发送的正文格式不正确。有没有一种方法可以不将其保存为文件然后发送?
尝试为服务图像本身设置正确的headers:
res.set('Content-Type', 'image/gif');
发送请求之前