Skip to Content

Regarding usage of Optical Character Recognition (OCR) API

Dec 01, 2017 at 11:10 AM


avatar image

Hi Team,

We were testing this new API (Optical Character Recognition (OCR) API) based on OCR technology and have 2 queries based on functionality/usage.

1.) Its "Try It Out" functionality works for .PDF files and correctly list out the contents as response. But it doesnt behave the same way for .jpeg or png files. The overview details state that it should be behaving the same way for .jpg or .pdf files, but it is not happening correctly.

2.) We are trying to test its functionality from the web full stack ide using the ui5 generated code but are facing some api connectivity issues. We tried to check the connection from the destination created but that too doesnt happen successfully. Is there any specific mapping required to be done so that api could be used.



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Dextor Developer Dec 14, 2017 at 07:04 AM

Hi S.K.

you can use this code for getting ocr work
getOCR: function(oEvent) {
			var sHeaders = {
				"Accept": "application/json",
				"APIKey": "Your api key"
			var url  = "";
			var data = new FormData();
                       // this is file object
			data.append('file', this.getView().byId("fileUploader").getFocusDomRef().files[0]);
			data.append('lang', "en");
			data.append('output_type', 'txt');

		onOCRDetectedSuccess: function(data) {
		onOCRDetectedFailed: function() {
			var ajaxRequest = {};
			ajaxRequest.url = /SAP_Leonardo_ML/ocr/ocr;
			ajaxRequest.method = "POST";
			ajaxRequest.headers = header; = data;
			ajaxRequest.processData = false;
			ajaxRequest.contentType = false;
			ajaxRequest.cache = false;
			ajaxRequest.success  = successcallback.bind(this);
			ajaxRequest.error = failcallback.bind(this);

Show 2 Share
10 |10000 characters needed characters left characters exceeded


I will try this code and let you know.

thanks for your help.




Hi there!

I was trying to use this API but it even doesnt work for PDF files. I tried a lot but I dont understand why it isnt working. I always get the http error 400(Bad Request). Maybe somebody of you can help me. That would be great!

That is my controller:

return Controller.extend("OCR.controller.view", {
		handleUploadPress: function(oEvent) {
			var oFileUploader = this.getView().byId("fileUploader");
			if (!oFileUploader.getValue()) {"Choose a file first");
			var that = this;
			var f = document.querySelector('input[type="file"]').files[0];
			//Create form object and append file to the same
			var data = new FormData();
			data.append('files', document.getElementById("__xmlview0--fileUploader-fu").files[0], document.getElementById(
			data.append('lang', "en");
			data.append('output_type', 'txt');
			var xhr = new XMLHttpRequest();

			xhr.addEventListener("readystatechange", function() {
				if (this.readyState === 4) {
					//var vjson = JSON.parse(this.responseText);
					//var label = vjson.predictions[0].results[0].label;
					//var score = vjson.predictions[0].results[0].score;
			});"POST", "");
		//"POST", "");
			xhr.setRequestHeader("APIkey", "----------------------------");
			xhr.setRequestHeader("Accept", "application/json");
Makoto Sugishita
Dec 14, 2017 at 04:13 AM

Hi SK,

I took screen shot and used the ".png" picture like this text.png and it worked fine.

I guess the accuracy would depend on the noises in the picture and could you try with the simple pictures with black characters and white background first?

About the destination, what kind of error did you face?




text.png (80.9 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded


I have followed steps similar to blog

and in it as per step 4 i.e destination configuration, we can add details of the sandbox url and click on check connection. When I add it in my trial account, I get below message -Failure reason: "Could not check at the moment. Please try again later"

Kindly advise.