繁体   English   中英

DocumentError“权限‘documentai.processors.processOnline’在资源‘我的处理器’上被拒绝(或者它可能不存在)

[英]DocumentError "Permission 'documentai.processors.processOnline' denied on resource 'my processors' (or it may not exist)

我正在尝试用 NodeJS 实现 documentai

我在尝试运行 DocumentProcessorServiceClient() 时卡住了

我收到这个错误

    Error: 7 PERMISSION_DENIED: Permission 'documentai.processors.processOnline' denied on resource '//documentai.googleapis.com/projects/<project-id>/locations/us/processors/<processor-id>' (or it may not exist).
      at Object.callErrorFromStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
      at Object.onReceiveStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\client.js:176:52)
      at Object.onReceiveStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:336:141)
      at Object.onReceiveStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:299:181)
      at C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\call-stream.js:130:78 
      at processTicksAndRejections (internal/process/task_queues.js:79:11) {
    code: 7,
    details: "Permission 'documentai.processors.processOnline' denied on resource '//documentai.googleapis.com/projects/<project-id>/locations/us/processors/<processor-id>' (or it may not exist).",
    metadata: Metadata { internalRepr: [Map], options: {} },
    note: 'Exception occurred in retry method that was not classified as transient'
  }

这是我的 function

const doScan = async (filePath: string) => {
  try {
    // Configure the request for processing the PDF
    const name = `projects/${projectId}/locations/${location}/processors/${processorId}`; 
    // Read the file into memory.
    const imageFile = await fs.promises.readFile(filePath); 
    // Convert the image data to a Buffer and base64 encode it.
    const encodedImage = Buffer.from(imageFile).toString("base64"); 
    const request = {
      name,
      document: {
        content: encodedImage,
        mimeType: "application/pdf",
      },
    };   
    // Recognizes text entities in the PDF document
    const [result] = await client.processDocument(request);  
    const { document }: any = result;
    const { text }: any = document;
    const getText = (textAnchor: any) => {
      if (!textAnchor.textSegments || textAnchor.textSegments.length === 0) {
        return "";
      } 
      // First shard in document doesn't have startIndex property
      const startIndex = textAnchor.textSegments[0].startIndex || 0;
      const endIndex = textAnchor.textSegments[0].endIndex; 
      return text.substring(startIndex, endIndex);
    }; 
    // Read the text recognition output from the processor
    console.log("The document contains the following paragraphs:");
    const [page1] = document.pages;
    const { paragraphs } = page1;

    for (const paragraph of paragraphs) {
      const paragraphText = getText(paragraph.layout.textAnchor);
      console.log(`Paragraph text:\n${paragraphText}`);
    }
  } catch (err) {
    console.log({ err });
  }
};

我已经尝试使用它更改名称,但它的结尾相同... client.processorPath(projectId, location, processorId);

谢谢

根据发布者的评论,通过升级到最新版本的 Document AI Node.JS Package 解决了这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM