Google Gmail 附件的文档 OCR

Google docs OCR on Gmail attachment

我正在尝试将 Gmail 附件的文本内容存储到 Google 云端硬盘。我按照此处提到的步骤操作并获得了一个基本的 OCR 脚本: https://medium.com/@aio.phnompenh/make-ocr-tool-in-google-spreadsheet-to-extract-text-from-image-or-pdf-using-google-app-script-c478d4062b8c

这会对以下 valueURL 中链接的图像执行 OCR:

var image = UrlFetchApp.fetch(valueURL).getBlob();

但是,当我尝试使用以下方法将其引用到 Gmail 附件时:

var image = GmailApp.getInboxThreads()[0].getMessages()[0].getAttachments();

我收到错误:

The mediaData parameter only supports Blob types for upload.

谁能告诉我如何解决这个问题?

此致。

.getAttachments() 函数 returns GmailAttachment[] 对象数组。要获得第一个附件,甚至是唯一一个附件,您需要这样做:

var image = GmailApp.getInboxThreads()[0].getMessages()[0].getAttachments()[0];