Ibm cloud 为什么我会得到;“无法推回”;尝试使用IBM Bluemix文档转换服务时出错?

Ibm cloud 为什么我会得到;“无法推回”;尝试使用IBM Bluemix文档转换服务时出错?,ibm-cloud,ibm-watson,document-conversion,Ibm Cloud,Ibm Watson,Document Conversion,我正在尝试使用带有Node.js应用程序的Bluemix文档转换服务转换文档。在我的应用程序中,除了错误之外,我什么都没有得到,但是我正在使用的测试文档在演示页面上可以很好地转换。下面是一个演示此问题的最小应用程序(请注意,虽然此应用程序正在从磁盘转换PDF,但“真实”应用程序无法执行此操作,因此缓冲区对象就是如此) “严格使用”; var fs=需要('fs'); var DocumentConversionV1=require('watson-developer-cloud/document

我正在尝试使用带有Node.js应用程序的Bluemix文档转换服务转换文档。在我的应用程序中,除了错误之外,我什么都没有得到,但是我正在使用的测试文档在演示页面上可以很好地转换。下面是一个演示此问题的最小应用程序(请注意,虽然此应用程序正在从磁盘转换PDF,但“真实”应用程序无法执行此操作,因此缓冲区对象就是如此)

“严格使用”;
var fs=需要('fs');
var DocumentConversionV1=require('watson-developer-cloud/documentconversion/v1');
var bluemix=require('./my_bluemix');
var extend=require('util')。\u extend//Node.js内置的对象扩展函数
var dcCredentials=extend({
url:“”,
版本:“v1”,
用户名:“”,
密码:“”
},bluemix.getServiceCreds('document_conversion');//VCAP_服务
var document_conversion=新DocumentConversionV1(dcCredentials);
var contents=fs.readFileSync('./testdoc.pdf',utf8');
帕姆斯变种={
文件:新缓冲区(内容,'utf8'),
转换目标:'应答单元'、/(JSON)应答单元、标准化的HTML或标准化的文本
内容类型:'application/pdf',
contentType:'application/pdf',//不知道这两种方法中的哪一种有效,似乎不一致,所以我将两者都包括在内
html到答案单位:{选择器:['h1','h2','h3','h4']},
};
console.log('文件的前100个字符:\n***************\n'+contents.substr(0100)+'\n******************\n');
文档转换。转换(参数、函数(错误、应答单位)
{
如果(!err)
console.log('Returned'+answerUnits.length);
其他的
log('Error:'+JSON.stringify(err));
});
针对测试PDF(782K)运行此程序的结果如下:

$node test.js
[DocumentConversion]警告:未指定版本日期。使用(可能是旧的)默认值。e、 g.watson.文件转换({版本日期:“2015-12-15”})
[DocumentConversion]警告:未指定版本日期。使用(可能是旧的)默认值。e、 g.watson.文件转换({版本日期:“2015-12-15”})
文件的前100个字符:
******************
%PDF-1.5
%����
10 obj
  • 通过在配置中指定版本日期,可以消除警告消息。有关示例,请参见测试

  • 如果文档通过演示进行了转换,但在使用应用程序时未能转换,则可能是二进制数据如何传递给服务的错误。(例如,它正在损坏或被截断。)您可以在这里看到演示的Node.js源代码。它可能会帮助您找出错误,或者为您提供不同的加载/发送文件的方法

  • 这是服务使用的一个基础库的错误。不幸的是,在这一点上,调用者无法调整


  • 事实证明,我把帕尔姆安排得很糟糕。正确的格式是{file:{value:newbuffer(contents),选项:{content_type:'application/pdf'},转换目标:'ANSWER_UNITS',配置:{conversion_target:'ANSWER_UNITS',//将html文件按“h2”、“h3”和“h4”标记html_拆分为(ANSWER)单位:{选择器:['h1','h2','h3','h4']}}}}}是的,转换\u target parm必须在那里两次!
    'use strict';
    
    var fs = require('fs');
    var DocumentConversionV1 = require('watson-developer-cloud/document-conversion/v1');
    var bluemix=require('./my_bluemix');
    var extend=require('util')._extend; //Node.js' built-in object extend function
    
    var dcCredentials =  extend({
      url: '<url>',
      version: 'v1',
      username: '<username>',
      password: '<password>'
    }, bluemix.getServiceCreds('document_conversion')); // VCAP_SERVICES
    var document_conversion = new DocumentConversionV1(dcCredentials);
    
    var contents = fs.readFileSync('./testdoc.pdf', 'utf8');
    
    var parms={
       file: new Buffer(contents,'utf8'),
       conversion_target: 'ANSWER_UNITS',     // (JSON) ANSWER_UNITS, NORMALIZED_HTML, or NORMALIZED_TEXT
       content_type:'application/pdf',
       contentType:'application/pdf', //don't know which of these two works, seems to be inconsistent so I include both
       html_to_answer_units: {selectors: [ 'h1', 'h2','h3', 'h4']},
       };
    console.log('First 100 chars of file:\n******************\n'+contents.substr(0,100)+'\n******************\n');
    document_conversion.convert(parms, function(err,answerUnits)
       {
       if (!err)
          console.log('Returned '+answerUnits.length);
       else
          console.log('Error: '+JSON.stringify(err));
       });
    
    $ node test.js
    [DocumentConversion] WARNING: No version_date specified. Using a (possibly old) default. e.g. watson.document_conversion({ version_date: "2015-12-15" })
    [DocumentConversion] WARNING: No version_date specified. Using a (possibly old) default. e.g. watson.document_conversion({ version_date: "2015-12-15" })
    First 100 chars of file:
    ******************
    %PDF-1.5
    %����
    1 0 obj
    <</Type/Catalog/Pages 2 0 R/Lang(en-US) /StructTreeRoot 105 0 R/MarkInfo<<
    ******************
    
    Error: {"code":400,"error":"Could not push back 82801 bytes in order to reparse stream. Try increasing push back buffer using system property org.apache.pdfbox.baseParser.pushBackSize"}
    $