cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CatCarrier
New Member

Posted PDFs are corrupt

Completely new to Power Automate:

 

My flow responds to the arrival of an email with a pdf attachment, and whose body contains certain key values, by POSTing that attachment to an api in a remote system. More precisely, it makes an api call to check if the remote system already has a row matching these keys, and if it does not, then it makes two more calls:

 

A. One api call to create a new row to contain these keys (this works fine)

B. Another api call, to a different endpoint, to attach the pdf to this new row <-- resulting pdf is corrupt

 

So (B) is a POST whose body is the content of the PDF.

 

All this runs fine end to end, but the pdf is unreadable (that is, as a pdf). If I compare it to the original (that is, in a text editor) they don't match. The file produced by (b) is also much larger, almost twice the size of the original.

 

I've already validated (not shown here) that there only one attachment, ending in pdf. Include Attachments is Yes.

 

Here I've created the new row (A) and I'm putting together the post to B.

 

CatCarrier_1-1620248122030.png

CatCarrier_3-1620248190012.png

CatCarrier_4-1620248339587.png

 

When I download the attachment content the input does not match the output, in that the output has a leading 'body' key.

 

CatCarrier_5-1620248888587.png

Input 

{"name":"attachmentContent","value":"%PDF-1.7\n%����\n4 0 obj\n<</Subtype/Image/Width 1728/

Output 

{"body":{"name":"attachmentContent","value":"%PDF-1.7\n%����\n4 0 obj\n<</Subtype/Image/Width 1728/

I also tried multipart, following several examples posted here, but the result was no different.

 

What's going on here? I appreciate your help!

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
CatCarrier
New Member

Here is the fix. It is similar to the fix described here.

 

The problem is this block where I populate attachmentContent. Somehow it gets all messed up, and I get back  content (not shown here) that looks like my pdf but is corrupted somehow, and is almost twice the correct length.

 

CatCarrier_0-1620334730182.png

 

So remove that variable and do this instead:

CatCarrier_1-1620335489193.png

Note that my flow is for cases where there is only a single attachment. I'm not sure what would happen if there were multiples.

I'm not sure why the Body presentation does not preserve the wrapping call to base64ToBinary() -- this looks like a bug -  but it works anyway.

 

 

View solution in original post

2 REPLIES 2
CatCarrier
New Member

Here is the fix. It is similar to the fix described here.

 

The problem is this block where I populate attachmentContent. Somehow it gets all messed up, and I get back  content (not shown here) that looks like my pdf but is corrupted somehow, and is almost twice the correct length.

 

CatCarrier_0-1620334730182.png

 

So remove that variable and do this instead:

CatCarrier_1-1620335489193.png

Note that my flow is for cases where there is only a single attachment. I'm not sure what would happen if there were multiples.

I'm not sure why the Body presentation does not preserve the wrapping call to base64ToBinary() -- this looks like a bug -  but it works anyway.

 

 

View solution in original post

alrez
Community Support
Community Support

Hi,

 

Thanks for your follow up post! I am glad that you were able to get this figured out. Hopefully this will prove useful for future communities users who are having similar issues. Remember to set the solution for this thread.

 

Regards,

 

Alex

 

-------

 

Community Support Team _ Alex Rezac
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (944)