【发布时间】:2016-01-08 16:03:20
【问题描述】:
我正在尝试使用 Watson 的 Document Conversion 服务将一些 PDF 文件转换为答案单元。这些文件都被压缩成一个大的 .zip 文件,该文件被上传到我的运行 Node.js 应用程序的 Bluemix 服务器。应用程序解压缩内存中的文件并尝试将每个文件依次发送到转换服务:
var document_conversion = watson.document_conversion(dcCredentials);
function createCollection(res, solrClient, docs)
{
for (var doc in docs) //docs is an array of objects describing the pdf files
{
console.log("Converting: %s", docs[doc].filename);
//make a stream of this pdf file
var rs = new Readable; //create the stream
rs.push(docs[doc].data); //add pdf file (string object) to stream
rs.push(null); //end of stream marker
document_conversion.convert(
{
file: rs,
conversion_target: "ANSWER_UNITS"
},
function (err, response)
{
if (err)
{
console.log("Error converting doc: ", err);
.
.
.
etc...
每次,转换服务都会返回错误 400,并带有描述“Web 应用程序中的错误”。
在摸索了两天试图找出这个相当无用的错误消息的原因之后,我几乎认为问题一定是转换服务无法确定正在发送的文件类型,因为没有与之关联的文件名。这当然只是我的猜测,但我无法测试这个理论,因为我不知道如何在不实际将每个文件写入磁盘并读回的情况下向服务提供该信息。
谁能帮忙?
【问题讨论】:
-
有趣...有人对此发表评论以询问更多信息,我发表评论以提供信息。然后第二天两个cmets都消失了。这在 Stack Overflow 上正常吗?
标签: node.js pdf stream ibm-cloud ibm-watson