cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Tex
Level: Powered On

Flow Custom Connector: Upload a file (POST , form-data)

Hi,

 

I am working with a REST API that requires POSTing a file.

 

In Postman, it works a treat. In the POST body, I set the key to "form-data" and for the value, I use the file picker to choose a file.

 

How do I replicate the file picker in the custom connector? In other words, what do I pass to the value field?

 

The files are actually in an Azure storage account, but I doubt value takes a file path. I am thinking that I will have to convert the file to a Byte array - somehow?

 

I'm undesided whether it makes a difference, but this particular API's Content-Type →text/xml; charset=utf-8. I only say that as most of the examples show JSON. In the simple GET requests, it has returned without issue.

 

I have exported and imported the Postman collection which goes a long way to providing the complete example. I just can't work out what I need to do to get the actual file up to the API server.

 

Any help will be greatly apreciated.

 

Thanks

 

W.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
paul_culmsee
Level 8

Re: Flow Custom Connector: Upload a file (POST , form-data)

You need to create an OpenAPI file... Attached is a generic one that I use for calling MSFlow and if you watch this video it will explain...

 

regards

 

Paul

 

https://www.youtube.com/watch?v=mp-8B1fLrqs

 

{
  "swagger": "2.0",
  "info": {
    "description": "Upload a Photo to SharePoint",
    "version": "1.0.0",
    "title": "PhotoHandler"
  },
  "host": "[enter host here]:443",
  "basePath": "/workflows",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/[enterid here]/triggers/manual/paths/invoke": {
      "post": {
        "summary": "Upload a Photo to SharePoint",
        "description": "Upload a Photo to SharePoint",
        "operationId": "UploadPhoto",
        "consumes": [
          "multipart/form-data"
        ],
        "parameters": [
          {
            "name": "api-version",
            "in": "query",
            "default": "2016-06-01",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "sp",
            "in": "query",
            "default": "/triggers/manual/run",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "sv",
            "in": "query",
            "default": "1.0",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "sig",
            "in": "query",
            "default": "[enter sig here]",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "Photo",
            "in": "formData",
            "description": "Photo to upload",
            "required": true,
            "type": "file"
          },
          {
            "name": "FileName",
            "in": "query",
            "description": "PictureName of uploaded file",
            "required": true,
            "type": "string"
          },
          {
            "name": "Latitude",
            "in": "query",
            "description": "Latitude of uploaded file",
            "required": true,
            "type": "string"
          },
          {
            "name": "Longitude",
            "in": "query",
            "description": "Longitude of uploaded file",
            "required": true,
            "type": "string"
          },
          {
            "name": "Description",
            "in": "query",
            "description": "Description of uploaded file",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation"
          }
        }
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {},
  "security": [],
  "tags": []
}

5 REPLIES 5
paul_culmsee
Level 8

Re: Flow Custom Connector: Upload a file (POST , form-data)

You need to create an OpenAPI file... Attached is a generic one that I use for calling MSFlow and if you watch this video it will explain...

 

regards

 

Paul

 

https://www.youtube.com/watch?v=mp-8B1fLrqs

 

{
  "swagger": "2.0",
  "info": {
    "description": "Upload a Photo to SharePoint",
    "version": "1.0.0",
    "title": "PhotoHandler"
  },
  "host": "[enter host here]:443",
  "basePath": "/workflows",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/[enterid here]/triggers/manual/paths/invoke": {
      "post": {
        "summary": "Upload a Photo to SharePoint",
        "description": "Upload a Photo to SharePoint",
        "operationId": "UploadPhoto",
        "consumes": [
          "multipart/form-data"
        ],
        "parameters": [
          {
            "name": "api-version",
            "in": "query",
            "default": "2016-06-01",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "sp",
            "in": "query",
            "default": "/triggers/manual/run",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "sv",
            "in": "query",
            "default": "1.0",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "sig",
            "in": "query",
            "default": "[enter sig here]",
            "required": true,
            "x-ms-visibility": "internal",
            "type": "string"
          },
          {
            "name": "Photo",
            "in": "formData",
            "description": "Photo to upload",
            "required": true,
            "type": "file"
          },
          {
            "name": "FileName",
            "in": "query",
            "description": "PictureName of uploaded file",
            "required": true,
            "type": "string"
          },
          {
            "name": "Latitude",
            "in": "query",
            "description": "Latitude of uploaded file",
            "required": true,
            "type": "string"
          },
          {
            "name": "Longitude",
            "in": "query",
            "description": "Longitude of uploaded file",
            "required": true,
            "type": "string"
          },
          {
            "name": "Description",
            "in": "query",
            "description": "Description of uploaded file",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation"
          }
        }
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {},
  "security": [],
  "tags": []
}

Community Support Team
Community Support Team

Re: Flow Custom Connector: Upload a file (POST , form-data)

Hi @Tex,

 

What is your current situation?

Does this issue resolved?

You may also take a look at the following example (Author is @paul_culmsee):

http://www.cleverworkarounds.com/2017/11/13/a-sample-openapiswagger-file-for-powerapps/

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Tex
Level: Powered On

Re: Flow Custom Connector: Upload a file (POST , form-data)

Hi @v-micsh-msft,

 

Thank you for your reply and sorry for my late reply.

 

I've been meaning to get to grips with Swagger. Once I have a working solution, I'll post here.

 

It is my (limited) understanding the Postman and Swagger are similar. I've been using the former and obvously hit a limited. 

 

Thanks again.

 

W.

Syam
Level: Powered On

Re: Flow Custom Connector: Upload a file (POST , form-data)

Hi

I followed this solution, and also the below link.

http://johnliu.net/blog/2017/7/building-non-json-webservices-with-flow

 

This is my OpenAPI file, which has a custom parameter "imgFile" - intended to pass the image file.

 

{
  "swagger": "2.0",
  "info": {
    "description": "Open API Connector to Upload the logo image to SharePoint",
    "version": "1.0.0",
    "title": "ImageUpload-v2",
    "termsOfService": "http://microsoft.com",
    "contact": {
      "name": "Syam Nair",
      "url": "http://microsoft.com",
      "email": "<<my email>>"
    },
    "license": {
      "name": "Appache 2.0",
      "url": "http://microsoft.com"
    }
  },
  "host": "prod-39.westus.logic.azure.com:443",
  "basePath": "/workflows",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/1003ff792e2549e7ba5b75199167da4c/triggers/manual/paths/invoke": {
      "post": {
        "summary": "Upload image to SharePoint Online",
	"description": "Upload image to SharePoint Online",
        "operationId": "UploadLogo",
	"consumes": [
	     "multipart/form-data"
	],
        "produces": [],
        "responses": {
          "202": {
            "description": "Accepted"
          }
        },
        "parameters": [
          {
            "name": "content-type",
            "in": "header",
            "description": "",
            "required": true,
            "type": "string"
          },
          {
            "name": "api-version",
            "in": "query",
            "type": "string",
            "description": "",
	    "default": "2016-06-01",
            "x-ms-visibility": "internal",
            "required": true
          },
          {
            "name": "sp",
            "in": "query",
            "type": "string",
            "description": "",
	    "default": "/triggers/manual/run",
            "x-ms-visibility": "internal",
            "required": true
          },
          {
            "name": "sv",
            "in": "query",
            "type": "string",
            "description": "",
	    "default": "1.0",
            "x-ms-visibility": "internal",
            "required": true
          },
          {
            "name": "sig",
            "in": "query",
            "type": "string",
            "description": "",
	    "default": "<<used the sig from the url>>",
            "x-ms-visibility": "internal",
            "required": true
          },		  		  
         {
            "name": "imgFile",
            "in": "formData",
            "type": "file",
            "description": "Image file to upload",
            "required": true
          }
        ]
      }
    }
  }
}

- The fow created is working when i invoke the URI from Postman (In body, i browsed the image file and send as POST request)

- But when calling the custom connector in PowerApp - I get the error "Method UploadLogo has an invalid value for parameter 'imgFile'"

- I inserted a "Add Picture" control and a button

- OnSelect of Button, i called the custom connector as 

 

 

'ImgUpload-v2'.UploadLogo(Img_Media_Ctrl.Media)

What am I missing? 

 

I see the PowerApps store a BlobManager string data of "Add Picture" media image.

appres://blobmanager/98332da9a48c4bd2a81c4da4c4d13e34/44

 

Any help on this is greatly appreciate.

 

Thank you in advance.

Syam

"

Super User
Super User

Re: Flow Custom Connector: Upload a file (POST , form-data)

Hi @Syam. Did you get this to work?