google-cloud-platform - 云文档 AI 无法处理存储中的文档
问题描述
我有以下代码:
const client = new DocumentProcessorServiceClient();
const inputConfig = {
mimeType: 'application/pdf',
gcsSource: {
uri: gcsSourceUri,
},
};
const outputConfig = {
gcsDestination: {
uri: gcsDestinationUri,
},
};
const name = `projects/myproject/locations/us/processors/myprocessor`;
const request = {
name,
inputConfigs: [inputConfig],
outputConfig: outputConfig
};
async function getText() {
const [operation] = await client.batchProcessDocuments(request);
};
getText();
这会产生以下错误:
(node:72144) UnhandledPromiseRejectionWarning: Error: Failed to process all the documents
at Operation._unpackResponse (E:\development\audiobook\node_modules\google-gax\build\src\longRunningCalls\longrunning.js:136:31)
at E:\development\audiobook\node_modules\google-gax\build\src\longRunningCalls\longrunning.js:122:18
(node:72144) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:72144) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
这里可能有什么问题?Cloud Storage URI 正常工作,文件格式正确。
解决方案
就我而言,问题是 outputConfig 的格式。
检查您的代码,我发现您正在以这种方式定义 outputConfig:
const outputConfig = {
gcsDestination: {
uri: gcsDestinationUri,
},
};
而根据文档 ,您应该将其更改为
const outputConfig = {
gcsDestination: {
gcsDestinationUri: 'gs://bucket-name/folder/',
},
};
推荐阅读
- jquery - 在 Liferay 7.2 中更新 jquery 版本
- swift - 如何从 SwiftUI 推送到现有的 UINavigationController 堆栈?
- python - 将值 n 拉到 df 中的最后一个值之前
- windows - 批处理 - 获取两个字符串之间的内容
- vb.net - Visual Studio ;新 System.Data.OleDb.OleDbConnection(strConString); 代码失败 - 我错过了什么?
- java - IntelliJ 2020.3 中未命中断点
- javascript - 滚动超过 1vh 后,jQuery 无法使导航图标出现
- plantuml - Plantuml 如何表示多案例决策节点?
- bash - Bash - 在 bash 函数中解析环境变量
- php - 联系表单向我显示 php 代码,而不是在提交时执行它