cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Custom connector with action that uses formdata to send file

I am trying to create a custom connector with an action that sends multipart/form-data with a parameter that is a file and receives JSON for the response.  But I am unable to get the correct format for the file parameter.  Flow is sending the binary contents of the file, but not setting the filename or the Content-Type.  Here is the JSON for the connector:

Any ideas of how to set this up? 

{
  "swagger": "2.0",
  "info": {
    "title": "Dynamic Signal",
    "description": "Your Mobile-First Company Communications Platform. Keep employees informed and engaged. Increase productivity and empower advocacy. This Connector allows for fluid communication between MS Flow and Dynamic Signals APIs. Full documentation available at dev.voicestorm.com",
    "version": "1.0"
  },
  "host": "crunchgranola.dsinitech.us",
  "basePath": "/v1",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/post/{id}/image": {
      "post": {
        "responses": {
          "200": {
            "description": "default",
            "schema": {
              "$ref": "#/definitions/successResponse"
            },
            "headers": {
              "Content-type:": {
                "description": "Content-type:",
                "type": "string"
              }
            }
          }
        },
        "summary": "Upload an image to a post",
        "description": "Sets the post image via MIME-multipart upload.",
        "operationId": "UploadImageToPost",
        "consumes": [
          "multipart/form-data"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "type": "string",
            "format": "uuid",
            "description": "The post ID",
            "x-ms-summary": "ID",
            "required": true,
            "in": "path",
            "name": "id"
          },
          {
            "name": "file",
            "in": "formData",
            "required": true,
            "type": "string",
            "format": "file",
            "x-ms-summary": "File Content"
          },
          {
            "name": "filename",
            "in": "formData",
            "required": true,
            "type": "string",
            "x-ms-summary": "File Name"
          },
          {
            "name": "Content-Type",
            "in": "formData",
            "required": true,
            "type": "string",
            "default": "image/jpeg",
            "x-ms-summary": "Content Type"
          }
        ]
      }
    }
  },
  "definitions": {
    "successResponse": {
      "type": "object",
      "description": "A simple response indicating the action was carried out successfully",
      "x-ms-summary": "",
      "properties": {
        "code": {
          "type": "string",
          "description": "A value of \"success\" indicates a successful operation",
          "x-ms-summary": "Code"
        }
      }
    }
  },
  "parameters": {},
  "responses": {},
  "securityDefinitions": {
    "api_key": {
      "type": "apiKey",
      "in": "header",
      "name": "Authorization"
    }
  },
  "security": [],
  "tags": []
}

 

 I am testing this with the following flow:

 

upload flow.PNG

6 REPLIES 6
Highlighted
Community Support
Community Support

Re: Custom connector with action that uses formdata to send file

Hi @DebDySi,

 

Do you want the result the "Upload an image to a post" action returned include the filename or the Content-Type within your flow?

Or 

Could you please share a bit more about your scenario?

 

If you want the result the "Upload an image to a post" action returned include the filename or the Content-Type within your flow, I think you should define the schema of the Response body within your Swagger OpenAPI definition file.

 

More details about the schema of the Response body within a Swagger file, please check the following article:

https://swagger.io/docs/specification/2-0/basic-structure/

 

More details about describing a Response within a OpenAPI definition file, please check the following article:

https://swagger.io/docs/specification/2-0/describing-responses/

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Regular Visitor

Re: Custom connector with action that uses formdata to send file

This is what I want flow to send (HTTP representation from Postman):

 

POST /v1/post/272fff76-59e5-4e44-a059-ea137a6964e1/image HTTP/1.1
Host: host.name.us
Authorization: Bearer <token>
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="sunny field.jpeg"
Content-Type: image/jpeg

<content>
------WebKitFormBoundary7MA4YWxkTrZu0gW--

 

Highlighted
Regular Visitor

Re: Custom connector with action that uses formdata to send file

The closest I could get was to define the "file" form parameter as type "file".  This causes flow to include the filename in the parameters for the file along with the file contents.  However, the content-type sent in the message body is "application/octet-stream", which is not even close to the content-type of the actual file.

 

Here is the updated swagger file:

{
  "swagger": "2.0",
  "info": {
    "title": "Dynamic Signal",
    "description": "Your Mobile-First Company Communications Platform. Keep employees informed and engaged. Increase productivity and empower advocacy. This Connector allows for fluid communication between MS Flow and Dynamic Signals APIs. Full documentation available at dev.voicestorm.com",
    "version": "1.0"
  },
  "host": "host.name.us",
  "basePath": "/v1",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/post/{id}/image": {
      "post": {
        "responses": {
          "200": {
            "description": "default",
            "schema": {
              "$ref": "#/definitions/successResponse"
            },
            "headers": {
              "Content-type:": {
                "description": "Content-type:",
                "type": "string"
              }
            }
          }
        },
        "summary": "Upload an image to a post",
        "description": "Sets the post image.",
        "operationId": "PostImage",
        "consumes": [
          "application/x-www-form-urlencoded"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "File",
            "in": "formData",
            "description": "Photo to upload",
            "required": true,
            "type": "file"
          },
          {
            "name": "Content-Type",
            "in": "formData",
            "description": "Content-Type of uploaded file",
            "required": true,
            "type": "string",
            "default": "image/jpeg"
          }
        ]
      }
    }
  },
  "definitions": {
    "successResponse": {
      "type": "object",
      "description": "A simple response indicating the action was carried out successfully",
      "x-ms-summary": "",
      "properties": {
        "code": {
          "type": "string",
          "description": "A value of \"success\" indicates a successful operation",
          "x-ms-summary": "Code"
        }
      }
    }
  },
  "parameters": {},
  "responses": {},
  "securityDefinitions": {
    "api_key": {
      "type": "apiKey",
      "in": "header",
      "name": "Authorization"
    }
  },
  "security": [],
  "tags": []
}

I added the "Content-Type" form parameter so our API could get the correct content-type, since MS Flow is sending the wrong type.

 

Here is what it looks like in request.bin:

FORM/POST PARAMETERS
Content-Type: image/jpeg

HEADERS
Total-Route-Time: 0

X-Ms-Apim-Callback: https://msmanaged-na.consent.azure-apim.net

X-Ms-Workflow-Version: 08586725344208734940

X-Ms-Workflow-Resourcegroup-Name: AECA5AE0AC704069B64FAA4E8879E7C1-CE462EF381A94DC78DEF6D57E01EB07A

Content-Length: 13958

X-Ms-Client-Tracking-Id: 08586725343708287641360760609CU08

X-Ms-Action-Tracking-Id: a980522a-e3eb-4235-b9aa-dadcbc4163f5

Authorization: Bearer Thisisatoken

User-Agent: azure-logic-apps/1.0 (workflow 00727f443b1243c48a7932d971d265f5; version 08586725344208734940)

X-Ms-Workflow-Run-Tracking-Id: 61763b8f-9534-4b3e-b967-c9d9aa3fee84

X-Ms-Execution-Location: westus

Content-Type: multipart/form-data; boundary="bf558f7b-d8b7-4f63-b7c1-d834caa621e3"

Connection: close

X-Ms-Apim-Referrer-Prefix: https://msmanaged-na.azure-apim.net/apim/test.20upload.20requestbin.5ff2537c5b409784ce.5f42368f7cfc1ecdb7/0d02d43a1fe64028aa9746e2197aeb64

Via: 1.1 vegur

X-Ms-Tracking-Id: ee4c6e7b-eec5-4c7b-9d9a-aec7e04ffb17

X-Ms-Workflow-Operation-Name: Upload_an_image_to_a_post

X-Request-Id: 1f6e56cf-9743-4f37-9f74-552d56e77a97

X-Ms-Workflow-System-Id: /locations/westus/scaleunits/prod-32/workflows/00727f443b1243c48a7932d971d265f5

X-Ms-Workflow-Id: 00727f443b1243c48a7932d971d265f5

Accept-Encoding: gzip,deflate

Host: debs-requestbin.herokuapp.com

X-Ms-Correlation-Id: ee4c6e7b-eec5-4c7b-9d9a-aec7e04ffb17

X-Ms-Client-Keywords: testFlow

Connect-Time: 0

X-Ms-Apim-Referrer: https://msmanaged-na.azure-apim.net/apim/test.20upload.20requestbin.5ff2537c5b409784ce.5f42368f7cfc1ecdb7/0d02d43a1fe64028aa9746e2197aeb64/10w0zv51

X-Ms-Client-Request-Id: ee4c6e7b-eec5-4c7b-9d9a-aec7e04ffb17

X-Ms-Workflow-Name: 147c1cb5-62e5-409c-9b5e-35b6a70fa858

X-Ms-Workflow-Subscription-Id: 9f3a0e5f-8058-487f-9d45-d3ff51164c54

X-Ms-Workflow-Run-Id: 08586725343708287641360760609CU08

X-Ms-Environment-Id: Default-aeca5ae0-ac70-4069-b64f-aa4e8879e7c1

Accept-Language: en-US

RAW BODY
--bf558f7b-d8b7-4f63-b7c1-d834caa621e3
Content-Disposition: form-data; name="File"; filename="sunflower.jpg"
content-type: application/octet-stream

ÿØÿàJFIFÿÛ„	
--end bf558f7b-d8b7-4f63-b7c1-d834caa621e3
Highlighted
Helper I
Helper I

Re: Custom connector with action that uses formdata to send file

Did you ever resolve this?

Highlighted
Regular Visitor

Re: Custom connector with action that uses formdata to send file

No, I never did.  I was pulled off onto other projects, and haven't looked at this in a year.

Highlighted
Frequent Visitor

Re: Custom connector with action that uses formdata to send file

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (10,252)