1

我正在使用计算机视觉 Api 并尝试使用节点 js 将图像从 url 发布到 ocr 微软认知服务,但我得到了

{"code":"InvalidImageUrl","requestId":"a4c68f18-37c1-484d-a044-2f89df963915","message":"Can't fetch the image."}

这是我的获取和发布代码

http.get(url.parse(imageUrl), function (res) {
    res.on('data',function (body) {
        console.log('data from get '+body);
      })    
    res.on('end', function () {


        request.post({
            headers: {                    
                'Ocp-Apim-Subscription-Key': proccess.env.SUBSKEY
            },
            url: 'http://api.projectoxford.ai/vision/v1.0/ocr?language=unk&detectOrientation=true',
            encoding: 'binary',
            formdata:{
                file:res
            }
        }, function (error, response, body) {
            if(error)
            {
                console.log(error);
            }
            console.log('data from post '+body);
        });
    });
});

我也在使用 botbuilder

4

1 回答 1

0

嗨,如果有人有同样的错误,我使用请求管道而不是 http get 并将发布选项移动到 var 来解决这个问题

request.get(imageUrl).pipe(request.post(postOptions,function(error,response,body) {  

           /*Do some cool stuff
            */
}
));
于 2017-01-08T02:19:06.970 回答