3

I'm using the watson-developer-cloud Node.js library to send HTML documents to Watson's Document Conversion service. The service tries to guess the mime/type for the documents that I'm sending but sometimes gets it wrong, so I want to specify the mime/type explicitly when making the call. I know the document conversion service's REST API has a way to specify the document type, but how do I specify the document type when using this call in the watson-developer-cloud library? The code below doesn't do it.

//"content" is the actual HTML
document_conversion.convert({file: {value: new Buffer(content), options: {}},
conversion_target: "ANSWER_UNITS",
type: "text/html"
}, function (err, response) {...
David Powell
  • 537
  • 1
  • 4
  • 16
  • Is this related to http://stackoverflow.com/questions/37104208/why-do-i-get-415-errors-from-watsons-document-conversion-service-on-certain-doc/37117066#37117066? – Daniel Toczala May 11 '16 at 13:39
  • It looks like this is not currently possible with the node SDK, but it probably should bee. I'm going to see if I can add support today. – Nathan Friedly May 11 '16 at 14:53

2 Answers2

1

The file.options.contentType trick works, but I just updated the library to make this "officially supported", with a bit friendlier syntax:

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

This should work with watson-developer-cloud v1.7.0 and newer.

Nathan Friedly
  • 7,837
  • 3
  • 42
  • 59
  • This does not seem to work any more. Please see my question http://stackoverflow.com/questions/37396428/how-do-i-send-a-pdf-to-watsons-document-conversion-service-without-writing-it-t – David Powell May 23 '16 at 16:54
0

Answering my own question here, for the benefit of future searchers.

Turns out that to do what I want to do, you have to put contentType:"text/html" in the options field, like this:

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

Many thanks to Joe Kozhaya for setting me straight on this.

David Powell
  • 537
  • 1
  • 4
  • 16