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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Custom Connector: How ...
Power Apps
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

 

Categories:
I have the same question (0)
  • ben11 Profile Picture
    18 on at

    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.

  • seadude Profile Picture
    1,855 on at

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

    image.png

  • ben11 Profile Picture
    18 on at

    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.

  • Cam Profile Picture
    185 on at

    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/

     

  • cachemerrill Profile Picture
    2 on at

    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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard