0

I am in need of batch processing documents. Here is my code:

  const { DocumentProcessorServiceClient } = require("@google-cloud/documentai").v1;
  const client = new DocumentProcessorServiceClient()
  const name = `projects/${projectId}/locations/${location}/processors/${processorId}`;
  const request = {
    name,
    inputDocuments: {
      gcsDocuments: {
        documents: [
          {
             gcsUri: 'gs://${bucketName}/1691859276860-958070983.pdf',
             mimeType: 'application/pdf'
          }
        ]
      },
    },
    documentOutputConfig: {
      gcsOutputConfig: {
        gcsUri: `${bucketName}/${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);

I matched the request type according to the doc correctly. texthttps://cloud.google.com/document-ai/docs/samples/documentai-batch-process-document

But I got this error message.

Error processing files: Error: 3 INVALID_ARGUMENT: Request contains an invalid argument.

I'm not sure what the problem is. I've tested the client.processDocument() with this credential based on the doc and it worked correctly. What did I do wrong?

Also I tried to find the correct request type of batch process document but there is no correct explanation.

halfer
  • 19,824
  • 17
  • 99
  • 186
DMOON
  • 1

1 Answers1

0

Your code looks right. I think that you're using an invaid value for documentOutputConfig. gcsOutputConfig.gcsUri? (${bucketName}/${gcsOutputUri}/${gcsOutputUriPrefix})

Note that this value must begin with gs:// and end with a trailing slash / as shown in the sample code.

Holt Skinner
  • 1,692
  • 1
  • 8
  • 21
  • Yes. That was my fault. I set the bucketName as simple bucketName and fogot to add "gs://". – DMOON Aug 17 '23 at 01:19