带有Node.js的Watson Dialog服务中的文件流暂停错误

时间:2016-01-22 15:31:07

标签: node.js stream ibm-watson watson-dialog

我正在尝试使用带有Node.js的IBM Watson Dialog服务。

我在这里关注Node.js的API参考https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/dialog/api/v1/?node#

根据这一点,创建对话框的方法是:

var fs     = require('fs');
var watson = require('watson-developer-cloud');
var dialog_service = watson.dialog({
  username: '{username}',
  password: '{password}',
  version: 'v1'
});

var params = {
  name: 'my-dialog',
  file: fs.createFileStream('template.xml')
};

dialog_service.createDialog(params, function(err, dialog) {
  if (err)
    console.log(err)
  else
    console.log(dialog);
});

但函数fs.createFileStream不存在,所以我使用fs.createWriteStream和相同的代码。

但是当我尝试运行时,我收到以下错误

/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:35
    source.pause();

TypeError: source.pause is not a function
    at Function.DelayedStream.create (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:35:12)
    at FormData.CombinedStream.append (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/lib/combined_stream.js:43:37)
    at FormData.append (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/form-data/lib/form_data.js:46:3)
    at appendFormValue (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/request.js:339:21)
    at Request.init (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/request.js:350:11)
    at new Request (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/request.js:140:8)
    at request (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/index.js:55:10)
    at createRequest (/home/ubuntu/workspace/node_modules/watson-developer-cloud/lib/requestwrapper.js:131:10)
    at Dialog.createDialog (/home/ubuntu/workspace/node_modules/watson-developer-cloud/services/dialog/v1.js:192:10)
    at Object.<anonymous> (/home/ubuntu/workspace/dialog.js:15:16)

为什么这个暂停功能不起作用的任何想法?该错误显示在watson-developer-cloud软件包的其中一个模块上,因此它不属于我的代码。

1 个答案:

答案 0 :(得分:3)

该功能为createReadStream()

参数应为:

var params = {
  name: 'my-dialog',
  file: fs.createReadStream('template.xml')
};

文档:fs.createReadStream()