Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Connector Development
Unanswered

Custom Connector: How to POST binary body?

(0) ShareShare
ReportReport
Posted on by 1,855

I have some tests working in Postman that POST binary data (.jpg) to an endpoint. This works just fine, but there is no visible schema for the `body` of this request. Its just "binary data" I guess. 

seadude_0-1629003025661.png

 

What do I select in PowerApps Custom Connector to allow binary data in the `body`? Do I need a schema of some sort? 

seadude_1-1629003162751.png

 

  • cachemerrill Profile Picture
    2 on at
    Re: Custom Connector: How to POST binary body?

    Certainly! Here's a detailed response suitable for a Microsoft forum on how to POST a binary body:

    ---

    To POST a binary body in an HTTP request, you need to ensure that the binary data is correctly formatted and sent to the server. This can be done using various tools and programming languages. Below, I'll demonstrate how you can achieve this using a few different methods:

    ### Using Postman

    Postman is a popular tool for testing APIs. Here’s how you can use it to POST a binary body:

    1. **Open Postman** and create a new POST request.
    2. **Enter the URL** to which you want to send the binary data.
    3. **Go to the Body tab**.
    4. Select **binary**.
    5. **Upload your binary file** by clicking on the "Select File" button.
    6. **Send the request** by clicking the "Send" button.

    ### Using cURL

    cURL is a command-line tool for transferring data using various network protocols. Here’s an example of how to POST a binary file using cURL:

    ```sh
    curl -X POST "http://example.com/upload" -H "Content-Type: application/octet-stream" --data-binary "@path/to/your/file"
    ```

    ### Using JavaScript (Node.js)

    Here’s an example using Node.js and the `axios` library to send a binary file in a POST request:

    1. **Install axios** if you haven’t already:

    ```sh
    npm install axios
    ```

    2. **Create a JavaScript file** and include the following code:

    ```javascript
    const axios = require('axios');
    const fs = require('fs');

    const url = 'http://example.com/upload';
    const pathToFile = 'path/to/your/file';

    const binaryData = fs.readFileSync(pathToFile);

    axios.post(url, binaryData, {
    headers: {
    'Content-Type': 'application/octet-stream',
    },
    })
    .then(response => {
    console.log('Response:', response.data);
    })
    .catch(error => {
    console.error('Error:', error);
    });
    ```

    ### Using Python

    Python’s `requests` library makes it easy to send HTTP requests, including binary data:

    1. **Install the requests library** if you haven’t already:

    ```sh
    pip install requests
    ```

    2. **Create a Python script** and include the following code:

    ```python
    import requests

    url = 'http://example.com/upload'
    file_path = 'path/to/your/file'

    with open(file_path, 'rb') as f:
    binary_data = f.read()

    headers = {
    'Content-Type': 'application/octet-stream',
    }

    response = requests.post(url, headers=headers, data=binary_data)

    print('Response:', response.content)
    ```

    ### Using .NET (C#)

    Here’s an example using C# to send a binary file in a POST request:

    1. **Create a new C# project** or use an existing one.
    2. **Include the following code**:

    ```csharp
    using System;
    using System.Net.Http;
    using System.Threading.Tasks;
    using System.IO;

    class Program
    {
    static async Task Main(string[] args)
    {
    var url = "http://example.com/upload";
    var filePath = "path/to/your/file";

    using var client = new HttpClient();
    using var content = new StreamContent(File.OpenRead(filePath));
    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

    var response = await client.PostAsync(url, content);

    var responseString = await response.Content.ReadAsStringAsync();
    Console.WriteLine("Response: " + responseString);
    }
    }
    ```

    Cache Merrill

    zibtek

  • Cam Profile Picture
    185 on at
    Re: Custom Connector: How to POST binary body?

    here is an example from Github:
    https://github.com/microsoft/PowerPlatformConnectors/blob/master/custom-connectors/ServiceNow/apiDefinition.swagger.json#L605

     

    there is an example POST on line 471 - 644,

    Cam_1-1653466483420.png

     

    631-640 contains the file element

    Cam_2-1653466607046.png



    i'm not sure what to make of this information.... but hopefully it helps someone 🙂

    (there is a content type element on row 611 - 630 too)

     

     

     

    note: the above is in JSON, so you will need to convert to YAML to use in your custom connector

    https://www.json2yaml.com/

     

  • ben11 Profile Picture
    18 on at
    Re: Custom Connector: How to POST binary body?

    Glad you figured yours out! I just edited my solution to note that I'm still getting an ominous warning. So far it's been working fine, but what I'm doing doesn't seem to be officially supported.

  • seadude Profile Picture
    1,855 on at
    Re: Custom Connector: How to POST binary body?

    I was able to figure this out. Believe it or not, the Body was not required!

    image.png

  • ben11 Profile Picture
    18 on at
    Re: Custom Connector: How to POST binary body?

    I had the same problem and finally figured it out. You can use the Swagger editor and add a body parameter like this:

          parameters:
          - name: body
            in: body
            schema: {type: string, format: binary}

     

    It appears as a string parameter in the swagger editor and on the custom connector testing tab, but then when you're in the actual flow editor you can put the "File content" from a previous step in there and it gets sent as plain binary. I absolutely did not expect that to work, but it does.

     

    Hope that helps anyone else stumbling across this post because they're stuck on the same thing!

     

    Edit: I later noticed that the paconn validate tool gives a warning that "the MIME type 'application/octet-stream' is not supported" when I try to set the content-type. So maybe what I discovered was a dirty hack, and not the intended behaviour after all.

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 770 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 494

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 399

Featured topics