cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MikeD1
Regular Visitor

HTTP Post - Forms Recognizer PDF file format issues

I'm using Forms Recognizer and have trained a model to extract keys from PDF attachments.  This works fine manually and I can extract the data from the JSON.  I used this to set this up:

https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/quickstarts/python-labeled...

 

The included Forms Recognizer actions in flow appear to not be updated to the latest versions and fail to find the model id, as seen here.  Using the HTTP calls in that post I am able to run an analysis using my trained model but I can't seem to find exactly how to send file attachments either from a Sharepoint List or an Email attachment.  Here is my HTTP POST:

 

Annotation 2020-08-17 175143.png

 

 

This returns a succeeded but all of the trained fields are 'null'.  If I try to take the actual contents of my get attachment operation I get a failed return of "The input data is not a valid image or password protected."  I'm not sure if I'm passing the file correctly to the HTTP POST call.  The current iteration of my flow does a dataURItoBinary on a base64 version of the file.  The form recognizer see this as a PDF file but doesn't parse the data correctly so I think I may have destroyed the contents of the file at that point with conversions, but unable to find something valid.  Is there a way to convert the pdf file to binary and then send it in the body of the POST or am I off base in trying to convert the file.  Here is the full flow:

 

Annotation 2020-08-17 175143.png

 

Thanks for any help. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Hello.

I have a custom connector that operates on the PDFs.

Generally, try creating expressions with the file content. Try every one of them. If flow stops working again try another one. There is plenty of issues with that.

String('Filecontent')

base64('Filecontent')

decodeBase64('Filecontent')

base64tostring('Filecontent')

base64tobinary('Filecontent')

 

One of them will work however It can stop working without any change.

 

I would recommend to create custom connector for that.

 

 

If my post was helpful don't forget about kudo me and mark my post as solution.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hey Mike, I followed you here from the other post.

In the other post I noticed in your print that you were sending the file in a slighlty different way than I did. I remember I had the same problem you're having now when I was seting up my flow.

The way I did it was to send "Attachements Content" on the Body. I might have changed it directly in code view, like this:
(for some reason I cant upload pictures to this answer, so i'll copy/paste the code view for the HTTP Post)

 

{
    "inputs": {
        "method": "POST",
        "uri": "https://<....>.cognitiveservices.azure.com/formrecognizer/v2.0-preview/custom/models/dbb5cbf3-15c3-4c57-86d9-574c9d665686/analyze",
        "headers": {
            "Content-Length": "",
            "Content-Type": "application/pdf",
            "Host": "<....>.cognitiveservices.azure.com",
            "Ocp-Apim-Subscription-Key": "<....>"
        },
        "body": "@base64ToBinary(string(items('For_each')?['ContentBytes']))"
    },
    "trackedProperties": {
        "Operation-Location": ""
    }
}

 

 
The important part is: "body": "@base64ToBinary(string(items('For_each')?['ContentBytes']))"

Can you give it a try?

Edit: Coudn't upload images because wasn't logged in
2020-08-18 07_42_23-Logic Apps Designer - Microsoft Azure.png2020-08-18 07_45_11-Logic Apps Designer - Microsoft Azure.png

Anonymous
Not applicable

Hello.

I have a custom connector that operates on the PDFs.

Generally, try creating expressions with the file content. Try every one of them. If flow stops working again try another one. There is plenty of issues with that.

String('Filecontent')

base64('Filecontent')

decodeBase64('Filecontent')

base64tostring('Filecontent')

base64tobinary('Filecontent')

 

One of them will work however It can stop working without any change.

 

I would recommend to create custom connector for that.

 

 

If my post was helpful don't forget about kudo me and mark my post as solution.

@Anonymous Thanks for the help.. you helped me a ton.  I couldn't ever get Flow to show the "Attachment Content" like in your flow.  What ended up working, thanks @Anonymous, was using base64toBinary on the file content directly.  Here is the HTTP call that worked:

MikeD1_2-1597767817044.png

 

Code view:

MikeD1_0-1597767770790.png

 

-Now to start parsing data.  Using this to automate some invoice processing to save my accounting team some manual headaches.. 

 

Thanks!

@Anonymous -Do you have a suggestion on where to start on creating a custom connector?  I found some microsoft documentation on creating one using azure logic apps, no sure if I'm barking up the wrong tree there. 

Anonymous
Not applicable

I think it's a new topic. Make new post and mark me there. I will try to help.

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (2,396)