Open nshganesh opened 1 month ago
Hi @nshganesh,
I'm not sure where the first screenshot comes from, but it's not on the https://cloud.google.com/document-ai/docs/process-documents-client-libraries page. The use of JSON and base64 is specific to an older endpoint for documentai, and does not apply to the code in https://cloud.google.com/document-ai/docs/process-documents-client-libraries. (If the documentation on https://cloud.google.com/document-ai/docs/process-documents-client-libraries links directly to that screenshot somewhere and implies that it is related, then that's misleading and it should be corrected; if you could point us to where that link is, that would help, because I wasn't able to locate it.)
If you're using the client libraries in https://cloud.google.com/document-ai/docs/process-documents-client-libraries then you should not be doing any base64 encoding. The error you're getting without base64 encoding suggests to me that the request actually did succeed. The error is actually happening when trying to pretty-print the response. It looks like there's a field somewhere in the response message that is a binary string but is being incorrectly marked as utf-8, which if true might indicate a bug in the protobuf library. As a workaround, I suggest, instead of printing or inspecting the response, just get the fields you're interested in.
HI @dazuma
Thank you so much for taking time to go through my issue. I actually went ahead with a nodejs client library. It works perfectly with base64 encoding and according to the documentation.
Sharing little more details about the problem however when I used ruby.
The screenshot I have shared is part of an authenticated page where we can create custom processors. Something like this https://console.cloud.google.com/ai/document-ai/locations/us/processors/[processorid].
I am not inspecting or printing from my part as such, even though the error message somehow suggests that. I also believe that there is some bug in the protobuf library just as you pointed it out.
https://cloud.google.com/document-ai/docs/process-documents-client-libraries following this documentation on making a request to individual document processing.
According to the below screenshot, we need to send a base64 encoded image.
But https://cloud.google.com/document-ai/docs/process-documents-client-libraries suggests without encoding approach.
content = File.binread file_path
Both approaches:
On making a request without base64 encoding, getting the below error:
On making a request with base64 encoding, getting the below error:
bin_file = File.binread file_path
content = Base64.strict_encode64(bin_file)