Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何处理来自Google的响应对象放置API-placesPhoto_Node.js_Google Places Api - Fatal编程技术网

Node.js 如何处理来自Google的响应对象放置API-placesPhoto

Node.js 如何处理来自Google的响应对象放置API-placesPhoto,node.js,google-places-api,Node.js,Google Places Api,我正在node.js中编写一个简单的包装器,它调用Goole Places API并使用photo_引用获取一张照片。当我运行这个程序并处理来自邮递员的请求时,它可以工作,但不显示照片本身。在下面的代码中,mapsClient.placesPhoto确实返回了一个包含许多标记的巨大响应。这不仅仅是原始图像数据。我的问题是如何从googleResp对象中提取图像或图像数据并将其发送回客户端 var googleMapsClient = require('@google/maps').createC

我正在node.js中编写一个简单的包装器,它调用Goole Places API并使用photo_引用获取一张照片。当我运行这个程序并处理来自邮递员的请求时,它可以工作,但不显示照片本身。在下面的代码中,mapsClient.placesPhoto确实返回了一个包含许多标记的巨大响应。这不仅仅是原始图像数据。我的问题是如何从googleResp对象中提取图像或图像数据并将其发送回客户端

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

    });
});

下面是我打印整个googleResp对象时得到的部分响应。缓冲区是否包含图像?如果是这样,我如何访问node.js IncomingMessage中的缓冲区{u readableState:readableState{objectMode:false,highWaterMark:16384,buffer:[],length:864,是的,从初始字节(ff d8 ff e0)判断,那里的缓冲区看起来像JPEG,或者至少是JPEG的开头。可能会有所帮助。