【发布时间】:2021-07-29 18:30:31
【问题描述】:
我正在尝试将要处理的 pdf 上传到 google 的 Document AI 服务。使用谷歌的“C#”使用 Google.Cloud.DocumentAI.V1。看了github和docs,信息不多。 PDF 位于本地驱动器上。我将pdf转换为字节数组,然后将其转换为Bystring。然后将请求 mime 设置为“application/pdf”,但它返回的错误是:
Status(StatusCode="InvalidArgument", Detail="Unsupported input file format.", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1627582435.256000000","description":"错误来自peer ipv4:142.250.72.170:443","file":"......\src\core\lib\surface\call.cc","file_line":1067,"grpc_message":"不支持的输入文件格式.","grpc_status":3}")
代码:
try
{
//Generate a document
string pdfFilePath = "C:\\Users\\maponte\\Documents\\Projects\\SettonProjects\\OCRSTUFF\\DOC071621-0016.pdf";
var bytes = Encoding.UTF8.GetBytes(pdfFilePath);
ByteString content = ByteString.CopyFrom(bytes);
// Create client
DocumentProcessorServiceClient documentProcessorServiceClient = await DocumentProcessorServiceClient.CreateAsync();
// Initialize request argument(s)
ProcessRequest request = new ProcessRequest
{
ProcessorName = ProcessorName.FromProjectLocationProcessor("*****", "mycountry", "***"),
SkipHumanReview = false,
InlineDocument = new Document(),
RawDocument = new RawDocument(),
};
request.RawDocument.MimeType = "application/pdf";
request.RawDocument.Content = content;
// Make the request
ProcessResponse response = await documentProcessorServiceClient.ProcessDocumentAsync(request);
Document docResponse = response.Document;
Console.WriteLine(docResponse.Text);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
【问题讨论】:
标签: c# artificial-intelligence cloud-document-ai