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

Community site session details

Session Id : Oltd/rszTqTUzYnlXjujSy
Power Automate - Building Flows
Suggested answer

HTTP How to Calculate Content-Length multipart/form-data Including Binary

Like (2) ShareShare
ReportReport
Posted on 20 Mar 2025 01:51:30 by
I'm working with a very obstinate API with arguably horrendous documentation (which is often also incorrect).  I'm fairly certain my Cloud Flow is failing to POST a request to it containing multipart/form-data because I'm not passing the Content-Length header, at least that's the only thing I can deduce comparing the trace output of a curl command that is able to make the request vs what I have in my HTTP action.
 
I've resorted to using the smallest jpg that I think is possible (107 bytes) to try to reduce the potential for error, however I still haven't found a way to accurately calculate what the Content-Length actually would be.
 
For context, the file is uploaded to a sharepoint site, and then needs to be sent to a third party API as binary.  So the reference to "Body" inside the body is actually the output from a Sharepoint Get File Contents action that happens before the API request.  Also the current Content-Length value is being set by a Compose step I've been using to try to calculate it.
 
Does anyone know how to calculate what the body would be including the binary that's in there?
 
 
BTW, this one is close, but I'm not sending it as Base64
Screenshot 2025-0...

Your file is currently under scan for potential threats. Please wait while we review it for any viruses or malicious content.

I have the same question (0)
  • Suggested answer
    Jon Unzueta Profile Picture
    1,344 Super User 2025 Season 2 on 03 Aug 2025 at 13:01:20
    HTTP How to Calculate Content-Length multipart/form-data Including Binary
     
    when dealing with multipart/form-data and binary uploads in Power Automate, especially to a poorly documented API, the lack of a Content-Length header can cause issues. Here's how you can approach this:

    âś… Understanding Content-Length in Multipart Requests

    The Content-Length header must reflect the total byte size of the entire HTTP body, including:

    • Boundary markers
    • Headers for each part
    • Binary content
    • Line breaks and formatting

    This is not just the size of the binary file, but the entire formatted multipart body.


    🛠️ How to Calculate Content-Length (Workaround)

    Since Power Automate doesn’t expose the raw byte size of the full HTTP body, you can try this workaround:

    Option 1: Use a Custom Azure Function or Logic App

    • Create an Azure Function that accepts the binary and builds the multipart body.
    • It can calculate the exact Content-Length and send the request.
    • Power Automate can call this function via HTTP.

    Option 2: Use a Prebuilt Tool to Simulate the Request

    • Use Postman or curl to build the request manually.
    • Capture the full request body and calculate its byte size.
    • Use that value in Power Automate’s HTTP header.

    Option 3: Estimate in Power Automate

    If you must stay within Power Automate:

    • Use length(outputs('Get_file_content')) to get the binary size.
    • Add estimated overhead for headers and boundaries (e.g., 300–500 bytes).
    • Use a Compose action to build the header:
    • {

        "Content-Length": "

      }

      ⚠️ This is not precise, but may work if the API is lenient.


      🔍 Additional Tips

    • Ensure your Content-Type header is set to:

    • multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
      

      (or whatever boundary you're using)

    • Make sure the binary is passed as-is, not Base64-encoded unless the API expects it.

    • Use â€śGet file content using path” from SharePoint to ensure you get the binary stream.

    🏷️ Tag me if you have any further questions or if the issue persists.

    ✅ Click "Accept as Solution" if my post helped resolve your issue—it helps others facing similar problems.

    ❤️ Give it a Like if you found the approach useful in any way.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 655 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 371 Moderator

#3
chiaraalina Profile Picture

chiaraalina 276

Last 30 days Overall leaderboard