Hello,
I’m using Document AI with the invoice_parser and I am trying to implement a FieldMask on my GcsOutputConfig but I get an error when I try to get the entities.type (or for that matter anything regarding entities). However with pages I have no problem, for instance with the pages.pageNumber property it returns me a JSON with the good result.
My PHP is as follows:
$documentProcessorServiceClient = new DocumentProcessorServiceClient(['apiEndpoint' => 'eu-documentai.googleapis.com']);
$name = $documentProcessorServiceClient->processorName($projectId, $location, $processor);
$gcsDocuments = new GcsDocuments();
$gcsDocument[] = new GcsDocument();
$gcsPrefix = new GcsPrefix();
$inputConfig = new BatchDocumentsInputConfig();
$gcsPrefix->setGcsUriPrefix('gs://{project_id}/{folder}/');
$gcsDocument[0]->setGcsUri('gs://{project_id}/{folder}/');
$gcsDocument[0]->setMimeType('application/pdf');
$gcsDocuments->setDocuments($gcsDocument);
$inputConfig->setGcsDocuments($gcsDocuments);
$inputConfig->setGcsPrefix($gcsPrefix);
$outputConfig = new DocumentOutputConfig();
$gcsOutputConfig = new GcsOutputConfig();
$fieldMask = new FieldMask();
$fieldMask->setPaths(['entities.type']); //NOT WORKING
$fieldMask->setPaths(['pages.pageNumber']); //WORKING
$fieldMask->setPaths(['entities']); //WORKING
$gcsOutputConfig->setGcsUri('gs://{project_id}/{folder}/jsons/');
$gcsOutputConfig->setFieldMask($fieldMask);
$outputConfig->setGcsOutputConfig($gcsOutputConfig);
$options = [
'inputDocuments' => $inputConfig,
'documentOutputConfig' => $outputConfig
];
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $documentProcessorServiceClient->batchProcessDocuments($name, $options);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var BatchProcessResponse $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
The error message display is :
Operation failed with error data: {"code":3,"message":"Failed to process all documents."}
Thanks for your help.
Allan
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |