【问题标题】:"Request has unsupported document format" - AWS Textract, using NodeJS“请求具有不受支持的文档格式” - AWS Textract,使用 NodeJS
【发布时间】:2021-09-17 08:15:54
【问题描述】:

我一直在尝试使用 AWS Textract(分析费用)在 AWS Lambda 中使用 NodeJS 14.x 和 AWS SDK 版本 2.966.0 创建一个算法。 这是我写的代码:

const AWS = require("aws-sdk")
const textract = new AWS.Textract({apiVersion: '2018-06-27'});
exports.handler = async (event) => {
  var params = {
    Document: {
      S3Object: {
        Bucket: '(REDACTED)',
        Name: 'test1.pdf'
      }
    }
  };
  try {
    const data = await textract.analyzeExpense(params).promise();
    return data;
  } catch(e) {
    return e;
  }
};

我收到错误:

{
  "message": "Request has unsupported document format",
  "code": "UnsupportedDocumentException",
  "time": "2021-08-11T22:07:59.913Z",
  "requestId": "f61104c6-fba6-4d97-8f5d-e4a4491a610b",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 62.83763773681126
}

我知道 PDF 通过异步 API 得到支持(而 JPEG 和 PNG 使用同步 API),但这不是已经异步了吗?如果没有,我如何异步调用它,让 textract 接受 PDF。

提前致谢。

【问题讨论】:

    标签: node.js amazon-web-services


    【解决方案1】:

    您收到错误是因为与 Amazon Textract 的同步操作不支持 PDF 格式。

    目前,Analyze Expense 仅支持同步请求,链接到documentation。

    如果您需要使用AnalyzeExpense 处理PDF 文件,一种方法是将PDF 拆分为多个.png 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      • 2015-05-19
      • 1970-01-01
      • 2020-06-09
      相关资源
      最近更新 更多