File type not recognised

Hi All,

I am trying read the ocr feedback into a table, but the result remains the same, no matter what I try.

I am using Microsoft Access:
Dim TmpData As String
Dim objOCRHTTP

Set objOCRHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
With objOCRHTTP
    .Open "POST", "https://api.ocr.space/parse/image", False
    .SetRequestHeader "apiKey", me.MyAPIKeyString
    .SetRequestHeader "content-type", "application/pdf"
    .SetRequestHeader "filetype", "pdf"
    .SetRequestHeader "file", Me.File
    .SetRequestHeader "iscreatesearchablepdf", fasle
    .SetRequestHeader "issearchablepdfhidetextlayer", false
    .SetRequestHeader "iscreatesearchablepdf", false
    .SetRequestHeader "istable", True
    .Send
    TmpData = .ResponseText
    If .Status <> 200 Then
    MsgBox .Status & " - " & .StatusText
    End If
    MsgBox TmpData
End With

I will write the result to the table when I get a result, but all my efforts have the same result:

image

I will appreciate your help sincerely.

Kind regards,
ajwonder

Hi @Admin,

Any response to this question, please?

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 Chrome app, see https://ocr.space/ocrapi#postman

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

Hi @Admin,

In Postman it works 100% as intended when I remove .SetRequestHeader “content-type”, “application/pdf”. I also discovered that the keys are case sensitive and changed apiKey to apikey

Dim TmpData As String
Dim objOCRHTTP

Set objOCRHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
With objOCRHTTP
    .Open "POST", "https://api.ocr.space/parse/image", False
    .SetRequestHeader "apiKey", me.MyAPIKeyString
    .SetRequestHeader "filetype", "pdf"
    .SetRequestHeader "file", Me.FileName
    .SetRequestHeader "iscreatesearchablepdf", True
    .SetRequestHeader "issearchablepdfhidetextlayer", False
    .SetRequestHeader "istable", True
    .Send
    TmpData = .ResponseText
    If .Status <> 200 Then
    MsgBox .Status & " - " & .StatusText
    End If
    MsgBox TmpData
End With

I still receive the same error in my application:
image

@Admin ???

Any feedback, please?

Hmm… if it works in Postman, this means the issue is somewhere inside your code, or?

Can I ask what you are doing? You are calling the API from inside Microsoft Access using VBA?

Hi @Admin,

Yes, as per the code I provided at the beginning of this thread, I execute it from MS Access.

You will note in the screen shot from Postman, compared to my code in MS Access, I call the same header requests (keys), with the same values and in both Postman and my application, even call the same file, but it is as if the [“file”, “filename.ext”] transaction in my code is not loading the file into operation.

In Postman you have the option to set a text/file option to allow you to “browse” for your document.

Do you know if you have a transaction type that may load the document if “file” is only a reference and not loaded natively?

Thank you in advance…