我正在尝试将存储在 Amazon S3 存储上的图像发送到 IBM Watson Visual Recognition Service。
我得到的错误是Error: Invalid JSON content received. Unable to parse.
以下代码在 Express 服务器上运行。
function (imgResult) {
var imgName = imgResult[0][0].imghash;
var params = {
images_file: s3.getObject(
{
Bucket: "Bucket Address",
Key: `upload/${imgName}`
}
).createReadStream()
};
visual_recognition.classify(params, function (err, res) {
if (err) {
console.log(err);
} else {
res.images[0].classifiers[0].classes.forEach(function (tagClass) {
db.raw(`INSERT INTO smartfolio.tags VALUES (null, ${imgid.idimages}, '${tagClass.class}')`)
.then(function (results) {
})
.catch(function (err) {
console.log(err)
})
});
}
});
}
在上面的代码中,imgResult 是来自数据库查询的响应,其中包含来自数据库的图像名称。我知道问题出在我的 params 变量上,但我对如何将图像从 S3 发送到 Watson 有点迷茫。
错误:
{ Error: Invalid JSON content received. Unable to parse.
at Request._callback (C:\Users\pheon\Desktop\Smartfolio-1\node_modules\watson-developer-cloud\lib\requestwrapper.js:74:15)
at Request.self.callback (C:\Users\pheon\Desktop\Smartfolio-1\node_modules\request\request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (C:\Users\pheon\Desktop\Smartfolio-1\node_modules\request\request.js:1081:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (C:\Users\pheon\Desktop\Smartfolio-1\node_modules\request\request.js:1001:12)
at IncomingMessage.g (events.js:292:16)
任何帮助将不胜感激。谢谢