web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Unexpected base64 hand...
Power Automate
Suggested Answer

Unexpected base64 handling

(0) ShareShare
ReportReport
Posted on by
Hi all,
  

I have a cloud flow with complex logic that processes a file, uploads it to an API and sends as an email attachment:

 

Pasted Graphic.jpg

  

Compose action is a simple

base64(items('Apply_to_each')?['contentBytes'])

It is then referenced in HTTP request and email action as

@outputs('base64')

This is how the data looks on a sample flow run:

 

WhatsApp Image 2025-10-27 at 12.29.29.jpeg

 

 

 

WhatsApp Image 2025-10-27 at 12.30.08.jpeg

 

WhatsApp Image 2025-10-27 at 12.30.54.jpeg

 

 

 

However, the data that arrives in the actual attachment is completely different:

 

 

 

WhatsApp Image 2025-10-27 at 12.31.23.jpeg

 

 

 

What is more confusing is that the data in the email attachment is a valid Base64 file, while the string sent to the API is not.

  
 

What kind of hidden transformation does PowerAutomate do to the data when it processes the email attachment? How do I force it to do the same to the API payload?

 
 
Categories:
I have the same question (0)
  • Suggested answer
    Sam_Fawzi Profile Picture
    904 Super User 2026 Season 1 on at
     
    Short answer: you double-encoded the file for the API. Use the original contentBytes for both the email attachment and the API, or convert to binary when posting raw.
    What’s happening

    items('Apply_to_each')?['contentBytes'] is already Base64.

    Your Compose uses base64( … ), which Base64-encodes that string again. Result = Base64 of a Base64 string (wrong for most APIs).

    The Outlook “Send an email (V2)” action is tolerant. It accepts Base64 and handles MIME wrapping, so your attachment arrives fine. Your API just receives the double-encoded string and flags it invalid.

    Fix

    Pick one of these patterns and keep it consistent.
    A
    ) Send Base64 inside JSON
    No conversions. Use the original field.
    // remove the Compose
    invoice64 : @{ items('Apply_to_each')?['contentBytes'] }
    If you must keep the Compose, set it to:
    @{ items('Apply_to_each')?['contentBytes'] }   // not base64(...)
     
    B) Send raw binary body (no JSON)
    Some APIs want the file bytes as the request body.
    Body: @{ base64ToBinary(items('Apply_to_each')?['contentBytes']) }
    Headers:
      Content-Type: application/pdf   // or the actual MIME type
     
    C) Normalize line breaks (rarely needed)
    If an API rejects CR/LF inserted by upstream systems:
    @{ replace(replace(items('Apply_to_each')?['contentBytes'], '\r',''), '\n','') }
    For the email attachment
    Use the same original contentBytes:

    Attachments Content → @{ items('Apply_to_each')?['contentBytes'] }

    Attachments Name → your filename

    Summary

    Do not call base64() on contentBytes.

    Use contentBytes as Base64 for JSON, or base64ToBinary(contentBytes) for raw uploads.

    Outlook’s action does MIME/Base64 wrapping; your API won’t.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 1,027

#2
Valantis Profile Picture

Valantis 809

#3
Haque Profile Picture

Haque 645

Last 30 days Overall leaderboard