0

I have the following code:

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();

Which produces the following error:

(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.

What might be the problem here? The Cloud Storage URI is working and the file is in the correct format.

double-beep
  • 5,031
  • 17
  • 33
  • 41
RuslanZab
  • 115
  • 2
  • 10

2 Answers2

0

In my case the problem was the format of outputConfig.

Checking your code I found you are defining the outputConfig this way:

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

while according to the documentation you should change it into

 const outputConfig = {
        gcsDestination: {
            gcsDestinationUri: 'gs://bucket-name/folder/',
        },
    };
Simone Bracaloni
  • 599
  • 4
  • 11
0

https://stackoverflow.com/a/65826292/6216983 is correct for v1beta3

For the GA version v1, you can find the updated request structure in the documentation:

https://cloud.google.com/document-ai/docs/send-request#documentai_process_document-nodejs

double-beep
  • 5,031
  • 17
  • 33
  • 41
Holt Skinner
  • 1,692
  • 1
  • 8
  • 21