You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Google Document AI处理W2/W9表单时随机报文档类型匹配错误如何解决

Google Document AI识别多类表单随机报错问题

错误表现

处理美国政府表单、W2表单、W9表单、发票、收据等多类表单时会随机触发如下报错:

  • Unable to find a document of type 'w2_', found 1 other document types
  • Unable to find a document of type 'w9_', found 1 other document types

该报错主要在处理W2 Form PDF文件时出现,其余部分类型PDF也偶有触发。

验证情况

起初怀疑是文件本身问题,经测试验证:

  • 同一份PDF直接上传至Google Cloud Platform控制台可正常识别
  • 仅通过代码调用时大概率报错,错误非必现,小概率可正常返回识别结果
  • 多次核对调用代码,完全符合谷歌官方文档要求,未发现逻辑错误

相关调用代码

const download_pdf = (bucketName, fileName) => {
  return new Promise(async (resolve, reject) => {
    //console.log("finalGS URL", `gs://${bucketName}/${fileName}`, "bucket:", bucketName, "fileName: ", fileName)

    const storage = new Storage()
    const bucket = storage.bucket(bucketName)
    const file = bucket.file(fileName)
    try {

      //download the file in memory
      const res = await file.download()

      let pdfBuffer = res?.flat()?.[0] || res?.[0]
      if (pdfBuffer) {
        resolve(pdfBuffer)
      } else {
        throw new Error(`Something went wrong when downloading file!`)
      }
    } catch (e) {
      console.error("error When Downloading Fiile ", e)
      reject(e)
    }

  })

}
const encodedImage = await download_pdf(bucket_name, file_name)
              
const request = {
    name,
    document: {
        content: encodedImage,
        mimeType: 'application/pdf',
    }

};

// Recognizes text entities in the PDF document
const [result] = await client.processDocument(request);
document = result?.document;

最新进展

目前该问题已在Google Cloud Platform Document AI控制台上传场景复现,初步判定为谷歌侧故障,已提交反馈等待官方回复,恳请社区提供可行解决方案。

内容的提问来源于stack exchange,提问作者Kashan Haider

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 18:33:01