Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not a valid base64 image

Tags:

enter image description here

I'm trying to semd a base64 encoded fimage to the ocr.space api following https://ocr.space/blog/2016/10/ocr-api-supports-base64.html and https://ocr.space/ocrapi . You can see my Postman settings in the screenshot.

However when I submit it I see:

"ErrorDetails": "Not a valid base64 image. The accepted base64 image format is 'data:<content_type>;base64,<base64_image_content>'. Where 'content_type' like 'image/png' or 'image/jpg' or 'application/pdf' or any other supported type.",

Using Postman I have created the following curl request https://pastebin.com/ajfC3a5r

What am I doing wrong

like image 207
user1592380 Avatar asked Sep 17 '18 02:09

user1592380


1 Answers

How about this modification?

Modification points:

  • In your base64 data at here, \n is included.
  • When I tried to decode the base64 data after \n was removed from the base64 data, it was found that the data was PDF file. The content type was not image/png.

By these, I think that the error which was shown at your question occurs. So please modify as follows.

Modified curl command:

  1. Please remove \n from the base64 data.
  2. About the header of base64 data, please modify from data:image/png;base64,##### base64 data ##### to data:application/pdf;base64,##### base64 data #####.

When above modifications were done, how about using the following curl command?

curl -X POST \
  https://api.ocr.space/parse/image \
  -H "apikey:#####" \
  -F "language=eng" \
  -F "isOverlayRequired=false" \
  -F "iscreatesearchablepdf=false" \
  -F "issearchablepdfhidetextlayer=false" \
  -F "base64Image=data:application/pdf;base64,##### base64 data #####"

Result:

When above sample is run, the following value is returned.

{
  "ParsedResults": [
    {
      "TextOverlay": {
        "Lines": [],
        "HasOverlay": false,
        "Message": "Text overlay is not provided as it is not requested"
      },
      "TextOrientation": "0",
      "FileParseExitCode": 1,
      "ParsedText": "##### text data #####",
      "ErrorMessage": "",
      "ErrorDetails": ""
    }
  ],
  "OCRExitCode": 1,
  "IsErroredOnProcessing": false,
  "ProcessingTimeInMilliseconds": "123",
  "SearchablePDFURL": "Searchable PDF not generated as it was not requested."
}

Note:

  • In my environment, I could confirm that the API worked using above modified base64 data and sample curl.

    • The curl sample including the modified base64 data is this.
    • If you use this, please set your API key.
  • Or you can also directly use the image file which is not base64 data. The sample curl is

      curl -X POST https://api.ocr.space/parse/image -H "apikey:#####" -F "[email protected]"
    
like image 104
Tanaike Avatar answered Sep 28 '22 17:09

Tanaike