2025 seems to be a terrible year for my blogging. Just my fourth post in four months!
A colleague reached out with a weird Logic App issue. They were trying to send an email with an attachment, and it was throwing this error:
1 2 3 4 5 6 7 8 9 10 |
{ "error": { "code": 500, "message": "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. \r\n at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)\r\n at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)\r\n at System.Convert.FromBase64String(String s)", "source": "logic-apis-canadacentral.azure-apim.net", "path": "choose[6]\\when[1]", "policyId": "", "clientRequestId": "cc738c22-721e-429a-92dd-1cee4c5d9598" } } |
The code was simple. An array variable had the contents of a file and they were attaching it to the Outlook connector.
The automation was originally setup in Power Automate, and the exact thing code worked there with no issue. But in Logic App, it fails.
Not sure what to do, I tried to replicate it “natively”. When inserting attachments with the “Send an email (V2)” connector, there’s two ways of doing it.
One – click on “Add new item” (below) and keep adding names and contents.
Or two, click on the “T” icon, and feed it an array with JSON. This is what my colleague was doing (and what I too would do when you have more than one attachment and want to add them via a loop, for instance).
To test what might be happening behind the scenes, I went with option 1 in the Logic App. That ran successfully, and when I looked at the output in the run history I saw what was different.
In Power Automate this block looks like this:
1 2 3 4 5 6 7 8 9 |
[ { "Name": "Invoice xxxx.pdf", "ContentBytes": { "$content-type": "application/octet-stream", "$content": "JVBERi0xLjcNJcjIyMjIyMgNMSAwIG9cMDAwV... } } ] |
But in Logic App it is:
1 2 3 4 5 6 7 |
[ { "Name": "Invoice xxxx.pdf", "ContentBytes": "JVBERi0xLjcNJcjIyMjIyMgNMSAwIG9cMDAwV... } } ] |
When I asked my colleague to change his Logic App to match the above, it too began working!
One would think things will be the same between Logic Apps and Power Automate, but there are subtle differences. Good to know.
base64 was just a red herring – Rakhesh Sasidharan