Facing issue while integrating ocr api inside salesforce

Hello There
I’m Facing issue while integrating API with Salesforce. While Calling ‘https://api.ocr.space/Parse/Image’ this API Facing “Image not base64” error but i’m passing image after converting into base64.
so could you please help for the same.
it’s an urgent requirement.

Thank you,
Nawal

The most likely reason is that something is wrong with your base64 string.

As a test, if you test the connection with Postman, do you get the same result?

You probably know it, but just in case: Postman is a free cross-platform app.

If you see the problem even with Postman, a screenshot of the result could be helpful.

In addition, this stackoverflow post might also help: Base 64 Image to ocr.space API

Yes it was working fine From Postman side with all the data parameter. But from Salesforce Side I’m trying with base64Image format so whatever data i’m passing from salesforce side it’s not working and it’s working from postman side so could you please help for the same. sharing the code of apex which is used inside salesforce

Code-

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setMethod(‘POST’);
request.setEndpoint(‘https://api.ocr.space/Parse/Image’);
request.setHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);
request.setHeader(‘apikey’, ‘REMOVED KEY’);
String body=‘isOverlayRequired=true&language=eng&base64Image=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAosAAACeCAIAAADVDNdBAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAqrSURBVHhe7dxNjttGGgbgOUiWcxqvfJYsfJYAPkrgoyQ3mIXhRRAgQIaSyGL9UqVuuv21/DyoFV0s1g+rXkmdmf/8CwDEI6EBICIJDQARSWgAiEhCA0BEEhoAIpLQABCRhAaAiCQ0AEQkoQEgIgkNABFJaACISEIDQEQSGgAiktAAEJGEBoCIJDQARCShASAiCQ0AEUloAIhIQgNARBIaACKS0AAQkYQGgIgkNABEJKEBICIJDQARSWgAiEhCA0BEEhoAIpLQABCRhAaAiCQ0AEQkoQEgIgkNABFJaACISEIDQEQSGgAiktAAEJGEBoCIJDQARCShASAiCQ0AEUloAIhIQgNARBIaACKS0AAQkYQGgIgkNABEJKEBICIJDQARSWgAiEhCA0BEEhoAIpLQABCRhAaAiCQ0A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Zx5Y+lWTKFMjbYfWe72nmppa0+uN2ZBThdupMrc640mopZrR9jhv6AkTuj1HsjJK6OK1rsrM7uptgHE3stsnd05tcvd2+9D8321O9yGdQXWZmaJVr0LqwFLyQz9dTxdnlumgzq2ds9a6V/ZUm3pKU200itv1yTZL/VW7TUV36UddukjTcin7YC9etPQ36Ymj4ecl609vaM3rPdPU1JpmiZuXx/p8d5aSVDPaHucNPWVCX3W2036gdN/XcpculdeXdWZ39TfAIt2ylvrno+mdU5rdvYtiA1/P5XpcD/WhnKWltD9UdO7adSvsi1Uc+ulZ3dje6lfD2Y6YrP39lu3ivUaOBpLuvVRO1Q5rXkvvKRftAt30r8+1WRuFbjGW3ahLi216l1KN92VLf9Um9OKls9epdrepYh4O1rQ+VYbb+Voee69qqWa0Pc4bet6E5kdIe7s81t/O1oHyTEkH6/3D7r7+YfezSGEwDKcftfSv8XOvKXFJaE60fnK///3gu+l9G9u/YZxy/v7Up/nws86PX/rXkNDEJKE5z/qj2afiz5NvLP+JsipnfIFe/Myneffn6IsIS/8KEpqYJDRnWb+qBviRc/s+l5UTe/Xznub7X2Grn7jjLP0LSWhiktAAEJGEBoCIJDQARCShASAiCQ0AEUloAIhIQgNARBIaACKS0AAQkYQGgIgkNABEJKEBICIJDQARSWgAiEhCA0BEEhoAIpLQABCRhAaAiCQ0AEQkoQEgIgkNABFJaACISEIDQEQSGgAiktAAEJGEBoCIJDQARCShASAiCQ0AEUloAIhIQgNARBIaACKS0AAQkYQGgIgkNABEJKEBICIJDQARSWgAiEhCA0BEEhoAIpLQABCRhAaAiCQ0AEQkoQEgIgkNABFJaACISEIDQEQSGgAiktAAEJGEBoCIJDQARCShASAiCQ0AEUloAIhIQgNARBIaACKS0AAQkYQGgIgkNABEJKEBICIJDQARSWgAiEhCA0BEEhoAIpLQABDPv//+H9wjRRvhGKqAAAAAAElFTkSuQmCC’;
request.setBody(body);
request.settimeout(6000);
system.debug('Request body '+body);
system.debug('Request ‘+Request);
HttpResponse response = http.send(request);
system.debug(’\n Response = ’ + response.getBody());

Error -
10:44:46:000 USER_DEBUG ponse = {“ParsedResults”:null,“OCRExitCode”:3,“IsErroredOnProcessing”:true,“ErrorMessage”:[“Not a valid base64 image. The accepted base64 image format is ‘data:image/<content_type>;base64,<base64_image_content>’.”],“ErrorDetails”:“Not a valid base64 image. The accepted base64 image format is ‘data:image/<content_type>;base64,<base64_image_content>’.”,“ProcessingTimeInMilliseconds”:“0”,“SearchablePDFURL”:null}

Try sending this as form-data, not as URL encoded, as mentioned in the anwer here: angularjs - Base 64 Image to ocr.space API Ionic 2 - Stack Overflow

Same way i was applied but still showing same error message please go through above code and error message

The code itself looks ok, but we (here) are no Salesforce experts. But I know that we have customers that use the OCR API with/from Salesforce successfully.

As another test: If you use a link to the image (URL option) instead of Base64, does this work?

Thanks for your reply But From salesforce side the URL not contains extension of file type so that is also one problem which i’m facing while integrating with OCR Api.

Can you please take help from your salesforce customer to resolve my problem or way which he is using this API, it will appreciable.

The solution for this is to use the filetype parameter. It overwrites the automatic file type detection based on content-type. Another Salesforce user that I have been in contact with recently is using the URL method + filetype, too.

You can test your URL at our online ocr form. It should work once you select the right file type (this is the same as the filetype parameter of the API):

Hi,

I am also facing same issue while integrating OCR API inside Salesforce.I am getting response in postman , But while integrating with salesforce getting error like NOT VALID BASE64 IMAGE. Also inserted filetype in my code.