问题描述
我正在尝试使用 NodeJS 实现文档
我在尝试运行 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'
}
这是我的功能
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);
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)