I am successfully creating and storing/saving plumsail docs from creation as a docx and then also converting them to pdf. After they come back I need to email them to an individual. So there would be an array of 2 converted plumsail pdf files ... I am using this technique here and sometimes it works and sometimes it doesn't work so when the recipient gets the email zero, one or both files are corrupted.
The workaround I heard is to specifically state the content-type ... in addition to the content as properties under contentBytes.
Add multiple attachments to an approval email with Power Automate
The first inspiration is well documented and is here ...
Send an email with multiple (0 – n) item attachments in Power Automate
So I thought I would try and see what the content-type is for the Plumsail pdf's. Thankfully I believe that is simply...
As far as I can tell there's nothing automated to tell me what the content-type is...application/pdf
So instead of this.. (this sometimes works and sometimes doesn't)
{
"Name": "CA_LetterOfEntry.pdf",
"ContentBytes": @{outputs('ConvertCALetterOfEntryToPDF')?['body/fileContent']}
}
I did this...
{
"Name": "USCA_CrossBorderLetter.pdf",
"content": {
"$content-type": "application/pdf",
"$content": @{outputs('Convert_CA2_DOCX_to_PDF')?['body/fileContent']}
}
}
But then outlook barks at me...I tried it with wrapping the @{outputs('Convert_CA2_DOCX_to_PDF')?['body/fileContent']} in quotes and without quotes...
OpenApiOperationParameterValidationFailed
The 'inputs.parameters' of workflow operation 'SendEmailToRequestorsCA' of type 'OpenApiConnection' is not valid. Error details: The API operation 'SendEmailV2' is missing required property 'emailMessage/Attachments/0/ContentBytes'.
I then tried...
{
"Name": "CA_LetterOfEntry.pdf",
"ContentType": "application/pdf",
"ContentBytes": @{outputs('ConvertCALetterOfEntryToPDF')?['body/fileContent']}
}
One file will open but the other doesn't, which makes me think I'm doing some wrong...I have triple checked my work. My process for creating the pdfs from docx is the same.
It seems the answer is this...I need to wrap the result file in base64ToBinary
base64ToBinary(@{outputs('ConvertCALetterOfEntryToPDF')?['body/fileContent']})
How to avoid corrupt email attachment in Power Automate
As soon as I did that it worked.
Ironically I only did it for one of the files in the array and both are now working.... I'm sharing this because ...
a) is it a bug with Plumsail's pdf file creator
b) I don't understand why that's not necessary on one file and why it is on another.
c) I'll add it to both to be safe as supposedly that ensures it's properly encoded.
