Not able to call OCR APi from Java

Hello Team,
I am trying to call OCR APi from java, but getting the below response
“{OCRExitCode=99, IsErroredOnProcessing=true, ErrorMessage=[Unable to recognize the file type, Unable to detect the file extension, or the file extension is incorrect, and no ‘file type’ provided in request. Please provide a file with a proper content type or extension, or provide a file type in the request to manually set the file extension.], ProcessingTimeInMilliseconds=0}”

I tried with file and base64Image but same response in both cases.

Please find the below code which I was trying to implement.

@SuppressWarnings({ “deprecation”, “resource” })
public static String getCaptchaData(String imagePath) {
final String url = “”;
try {
FormBodyPart cmisactionPart_1 = FormBodyPartBuilder.create(“language”, new StringBody(“eng”, ContentType.TEXT_PLAIN)).build();
FormBodyPart cmisactionPart_2 = FormBodyPartBuilder.create(“isOverlayRequired”, new StringBody(“false”, ContentType.TEXT_PLAIN)).build();
FormBodyPart cmisactionPart_3 = FormBodyPartBuilder.create(“iscreatesearchablepdf”, new StringBody(“false”, ContentType.TEXT_PLAIN)).build();
FormBodyPart cmisactionPart_4 = FormBodyPartBuilder.create(“issearchablepdfhidetextlayer”, new StringBody(“false”, ContentType.TEXT_PLAIN)).build();
FormBodyPart cmisactionPart_5 = FormBodyPartBuilder.create(“filetype”, new StringBody(“png”, ContentType.TEXT_PLAIN)).build();
FormBodyPart cmisactionPart_6 = FormBodyPartBuilder.create(“scale”, new StringBody(“true”, ContentType.TEXT_PLAIN)).build();

		//Base64 Start
		FileInputStream stream = new FileInputStream(imagePath);
		int bufLength = 2048;
	    byte[] buffer = new byte[2048];
	    byte[] data;

	    ByteArrayOutputStream out = new ByteArrayOutputStream();
	    int readLength;
	    while ((readLength =, 0, bufLength)) != -1) {
	        out.write(buffer, 0, readLength);

	    data = out.toByteArray();
	    String imageString = "data:image/png;base64,"+Base64.getEncoder().withoutPadding().encodeToString(data);
		System.out.println("data :-" +imageString);
		FormBodyPart cmisactionPart_7 = FormBodyPartBuilder.create("base64Image", new StringBody(imageString, ContentType.TEXT_PLAIN)).build();
		//Base64 End
		MultipartEntity reqEntity = new MultipartEntity();
		FileBody image_1 = new FileBody(new File(imagePath));
		ContentBody image = new FileBody(new File(imagePath));
		reqEntity.addPart("file", image_1);
		HttpPost httpPost = new HttpPost(url);
		httpPost.setHeader("apikey", "helloworld");
		HttpClient httpClient = new DefaultHttpClient();
		HttpResponse response = httpClient.execute(httpPost);
		HttpEntity resEntity = response.getEntity();
		String resultString = EntityUtils.toString(resEntity);		
		return resultString;
	} catch (Exception e) {
	return imagePath;

Can you please help me to fix the issue.

Hi, 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 app, see Free OCR API

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