node.js - AWS 服务的文本提取方法“getDocumentTextDetection”只返回“JobStatus”,没有其他响应
问题描述
我正在尝试使用 aws-sdk 的服务 Textract.getDocumentTextDetection 对 pdf 文件进行文本提取,其中我正在传递由方法“startDocumentTextDetection”返回的 JobId。
首先,我尝试使用 s3 服务的方法“upload”上传图像/pdf,该方法成功运行并返回我这样的响应
{
ETag: '"9d022c9c496f2663d2fgv45d181e475"',
Location:
'https://bucket-name.s3.amazonaws.com/beacon-logo.png',
key: 'beacon-logo.png',
Key: 'beacon-logo.png',
Bucket: 'bucket-name'
}
在此之后,我调用 textract 的方法“startDocumentTextDetection”来获取 JobId,它返回给我这个:
{ JobId:
'11df404ce0fa7c958ba23579890a52388132a01d326802a1eggh76915c55qw1e' }
在此之后,我调用 AWS 服务的另一种方法“getDocumentTextDetection”从上传的文件中提取单词,该文件返回给我对象:
{ JobStatus: 'IN_PROGRESS' }
这是错误的。方法“getDocumentTextDetection”应返回如下内容: https ://docs.aws.amazon.com/textract/latest/dg/API_GetDocumentTextDetection.html
以下是到目前为止编写的所有代码:
const textract = new AWS.Textract({
apiVersion: "2018-06-27",
accessKeyId: "my-access-key-id",
secretAccessKey: "my-secret-access-key",
region: "region",
ACL: "public-read"
});
const s3 = new AWS.S3();
router.post("/", function (req, res, next) {
const paramsS3Upload = {
Bucket: "bucket-name",
Key: req.files.document.name,
ACL: "public-read",
ContentType: req.files.document.mimetype,
Body: req.files.document.data
};
var s3options = {
partSize: 10 * 1024 * 1024,
queueSize: 1
};
s3.upload(paramsS3Upload, s3options, function (s3Err, s3data) {
if (s3Err) throw s3Err;
var params = {
DocumentLocation: {
S3Object: {
Bucket: s3data.Bucket,
Name: s3data.Key,
Version: s3data.VersionId
}
},
NotificationChannel: {
RoleArn: "arn:aws:iam::id:role/role-name",
SNSTopicArn: "arn:aws:sns:region:id:topic-name"
}
};
textract.startDocumentTextDetection(params, function (err, data) {
if (err) console.log(err, err.stack);
else {
var textDetectionParams = {
JobId: data.JobId
};
textract.getDocumentTextDetection(textDetectionParams, function (
err,
textDetectData
) {
if (err) console.log(err, err.stack);
else {
console.log(textDetectData); // Not getting proper response here!!
res.send({
data: textDetectData
});
}
});
}
});
});
});
预期的输出应该是这样的: https ://docs.aws.amazon.com/textract/latest/dg/API_GetDocumentTextDetection.html 。无法弄清楚出了什么问题。
解决方案
推荐阅读
- kubernetes - 将传入流量路由到具有在 URL 中指定的标签的 pod
- reactjs - 播放器组件在循环渲染时播放回声
- git - 在 Azure DevOps 上检查分支是否仅通过合并提交领先
- python - Windows Apache 停止工作并且不再启动 - “httpd.exe -k start”不给出错误
- magento2 - Magento 2选择查询显示产品sku但某些产品未显示在前端
- python - 无法在 python 中安装“Fury”
- android - 我需要更新或更改我的 gradle 文件中的任何内容吗?
- django - 如何将 Django 用于具有管理门户的 SaaS 产品?
- python - 使用字典更新索引值列
- azure - 在 Azure Web App 上运行的 PowerShell 脚本,有可能吗?