首页 > 解决方案 > 云文档 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 正常工作,文件格式正确。

标签: google-cloud-platform

解决方案


就我而言,问题是 outputConfig 的格式。

检查您的代码,我发现您正在以这种方式定义 outputConfig:

const outputConfig = {
    gcsDestination: {
        uri: gcsDestinationUri,
    },
};

而根据文档 ,您应该将其更改为

 const outputConfig = {
        gcsDestination: {
            gcsDestinationUri: 'gs://bucket-name/folder/',
        },
    };

推荐阅读