node.js - GCP 文档 AI 示例不起作用 - 接收 INVALID_ARGUMENT:请求包含无效参数
问题描述
错误出现在 batchProcessDocuments 行并且有错误:
{
code: 3,
details: 'Request contains an invalid argument.',
metadata: Metadata {
internalRepr: Map { 'grpc-server-stats-bin' => [Array] },
options: {}
},
note: 'Exception occurred in retry method that was not classified as transient'
}
我试图尽可能多地复制这个例子,但没有成功。有没有办法找到有关所需输入参数的更多信息?在网络上使用 Document AI 的例子很少,这是一个新产品。
这是我的代码示例:
const projectId = "95715XXXXX";
const location = "eu"; // Format is 'us' or 'eu'
const processorId = "a1e1f6a3XXXXXXXX";
const gcsInputUri = "gs://nmm-storage/test.pdf";
const gcsOutputUri = "gs://nmm-storage";
const gcsOutputUriPrefix = "out_";
// Imports the Google Cloud client library
const {
DocumentProcessorServiceClient,
} = require("@google-cloud/documentai").v1beta3;
const { Storage } = require("@google-cloud/storage");
// Instantiates Document AI, Storage clients
const client = new DocumentProcessorServiceClient();
const storage = new Storage();
const { default: PQueue } = require("p-queue");
async function batchProcessDocument() {
const name = `projects/${projectId}/locations/${location}/processors/${processorId}`;
// Configure the batch process request.
const request = {
name,
inputConfigs: [
{
gcsSource: gcsInputUri,
mimeType: "application/pdf",
},
],
outputConfig: {
gcsDestination: `${gcsOutputUri}/${gcsOutputUriPrefix}/`,
},
};
// Batch process document using a long-running operation.
// You can wait for now, or get results later.
// Note: first request to the service takes longer than subsequent
// requests.
const [operation] = await client.batchProcessDocuments(request); //.catch(err => console.log('err', err));
// Wait for operation to complete.
await operation.promise();
console.log("Document processing complete.");
}
batchProcessDocument();
解决方案
我认为这是解决方案:https ://stackoverflow.com/a/66765483/15461811
(你必须设置apiEndpoint
参数)
推荐阅读
- reactjs - React / Material-UI:在自定义主题中使用变量引用
- powershell - 在发送带有附件的电子邮件的脚本结束后,PowerShell 仍会锁定文件
- sparql - 有没有办法只返回维基数据中日期的已知精度?
- mysql - MySQL EAV 数据库:索引未用于使用 OR 和 LEFT JOIN 的查询(Wordpress DB)
- flutter - Flutter视频播放器检查视频是否静音
- r - 错误:参数 1 必须有名称。在 r 中使用 map_drf 时
- android - Flutter 在验证表单时抛出错误
- angularjs - 如何使用 Express 和 Angular 在 URL 中创建查询参数?
- r - 子集错误:较长的对象长度不是较短对象长度的倍数
- swift - 停止接收(取消订阅)来自 AWS Amplify 的所有突变更新