使用watson-developer-cloud Node.js库的convert函数时,如何指定原文档的mime类型?

When using the convert function of the watson-developer-cloud Node.js library, how do I specify the mime type of the original document?

我正在使用 watson-developer-cloud Node.js 库将 HTML 文档发送到 Watson 的文档转换服务。该服务尝试猜测我正在发送的文档的 mime/type,但有时会出错,因此我想在进行调用时明确指定 mime/type。我知道文档转换服务的 REST API 有指定文档类型的方法,但是 在 watson-developer-cloud 库中使用此调用时如何指定文档类型? 下面的代码不这样做。

//"content" is the actual HTML
document_conversion.convert({file: {value: new Buffer(content), options: {}},
conversion_target: "ANSWER_UNITS",
type: "text/html"
}, function (err, response) {...

为了未来搜索者的利益,在这里回答我自己的问题。

原来要做我想做的事,你必须把contentType:"text/html"放在选项字段中,像这样:

//"content" is the actual HTML
document_conversion.convert({file: {value: new Buffer(content), options: {contentType: "text/html"}},
conversion_target: "ANSWER_UNITS"
}, function (err, response) {...

非常感谢 Joe Kozhaya 让我明白这一点。

file.options.contentType 技巧有效,但我刚刚更新了库以使用更友好的语法来制作此 "officially supported":

document_conversion.convert({
  file: new Buffer(content),
  content_type: "text/html",
  conversion_target: "ANSWER_UNITS"
}, function (err, response) {
  //...
});

这应该适用于 watson-developer-cloud v1.7.0 和更新版本。