我正在尝试使用 Node.js watson-developer-cloud JDK 将 JSON 文档插入到 Discovery 集合中。这是相关代码:
var DiscoveryV1=require('watson-developer-cloud/discovery/v1');
var discovery=new DiscoveryV1(credentials);
let doc=aSmallValidJsonObject;
let parms={
environment_id: envID,
collection_id: collID,
configuration_id: confID,
file: {
value: new Buffer(JSON.stringify(doc)),
options:{
contentType:'application/json',
"Content-Type":'application/json' //just to be sure
}
}
};
discovery.addDocument(parms,
function(err,results)
{
if (err) {...
此调用返回的错误是
"Error: Request must specify either a "metadata" or "file" part"
我也试过用这种方式制作parms:
let parms={
environment_id: envID,
collection_id: collID,
configuration_id: confID,
metadata:{"Content-Type":"application/json"},
file:new Buffer(JSON.stringify(doc))
};
在这种情况下我得到的错误是
[TypeError: source.on is not a function]
(我将此错误追溯到库延迟流.js中的第 33 行)
如果我在上述参数中将元数据字段设为字符串(即,将值括在单引号中),则会收到此错误:
Error: The Media Type [application/octet-stream] of the input document is not supported. Auto correction was attempted, but the auto detected media type [text/plain] is also not supported. Supported Media Types are: application/json, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/pdf, text/html, application/xhtml+xml
有人能告诉我这个函数的正确语法是什么吗?