Document AI Contract Processor batchProcessDocuments忽略fieldMask问题排查
问题原因及解决方法
你的请求参数中额外添加了region字段,但BatchProcessDocumentsRequest的官方参数结构里并没有这个字段,这会导致请求解析异常,进而使fieldMask的过滤设置未被生效。
此外,name参数已经包含了区域信息(projects/XXX/locations/us/processors/3e85a4841d13ce5),完全不需要单独指定region。
修正后的代码
const documentai = require('@google-cloud/documentai').v1; const client = new documentai.DocumentProcessorServiceClient(options); let params = { "name": "projects/XXX/locations/us/processors/3e85a4841d13ce5", "inputDocuments": { "gcsDocuments": { "documents": [{ "mimeType": "application/pdf", "gcsUri": "gs://bubble-bucket-XXX/files/CymbalContract.pdf" }] } }, "documentOutputConfig": { "gcsOutputConfig": { "gcsUri": "gs://bubble-bucket-XXXX/ocr/" }, "fieldMask": { "paths": [ "entities" ] } } }; client.batchProcessDocuments(params, function(error, operation) { if (error) { return reject(error); } return resolve({ "operationName": operation.name }); });
额外检查项
- 确保使用的
@google-cloud/documentaiSDK是最新版本,旧版本可能存在fieldMask的兼容性问题,可通过npm update @google-cloud/documentai更新。 - 确认
fieldMask.paths的路径正确:对于Contract Processor返回的顶级entities数组,["entities"]的设置是正确的,会仅保留该字段,自动排除content(Base64图片)、pages等不需要的内容。
内容的提问来源于stack exchange,提问作者redvivi
相关产品推荐
相关产品推荐

