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

Custom API to file upload

Hi,

 

I have been playing with the Microsoft Flow for a few days to implement one of our business sceneario.

 

We have cloud solution something that manages documents. Something similar to Google Drive/Dropbox

 

What i am trying to demonstrate is when a new file is created in Sharepoint(Office 365), i want that file to be upload into our application. In order to do that we created custom api with the following swagger definition. Unfortunately i am not able to get it working

 

I compared the input messages between our custom api flow and dropbox flow. Both of them differs

 

In Dropbox i see as follows

 
 

Screen Shot 2017-01-27 at 12.30.23.png

And in our custom api i see as follows

Screen Shot 2017-01-27 at 12.29.29.png

 

Now my question is what should be swagger definition for file upload. Currently my swagger definition for the service looks like as follows

 

 

/{community_id}/rooms/{room_id}/content/{id}/children:
    post:
      operationId: uploadFile
      summary: Upload single file to folder
      description: |
        The single file upload endpoint çreates file in folder.
        The response includes status and meta info about created file.
      security:
        - OauthSecurity: []
      consumes:
        - application/octet-stream # and/or application/x-www-form-urlencoded
      parameters:
        - $ref: "#/parameters/community_id"
        - $ref: "#/parameters/room_id"
        - $ref: "#/parameters/id"
        - name: file
          in: body
          description: Uploaded file data
          required: true
          schema:
            $ref: '#/definitions/File'
        
      tags:
        - Upload file
      responses:
        '200':
          description: File is succesfully uploaded
        '400':
          $ref: "#/responses/ValidationError"
        '401':
          $ref: "#/responses/AuthenticationError"
        '403':
          $ref: "#/responses/AuthorizationError"
        '404':
          $ref: "#/responses/NotFoundError"
        '500':
          $ref: "#/responses/UnexpectedError"

definitions:

  File:
    description: The file object
    type: object
    properties:
      name: 
        description: Name of file
        type: string
      file: 
        description: File content
        type: string
5 REPLIES 5
Power Automate Staff SameerCh
Power Automate Staff

Re: Custom API to file upload

You didnt mention how your API works.  The swagger definition will depend on how your custom API works, rather than making it similar to that of Dropbox.

 

Specifically, it looks like your API is expecting a JSON payload with two fields: "name" and "file", which is a string.  If you are trying to transfer a binary file into a JSON string, you must encode it.  You can use base64 encoding, and your API will have to decode it.  In that case, you will use an additional property called "format" with the value "byte".

 

      file:
        description: File content
        type: string

        format: byte

 

The Dropbox Connector, OTOH does things slightly different.  It takes the filename as a query parameter and takes the binary blob of the file content in the request payload.  A format of 'binary' is used to describe that (although there is a debate that it may not be the correct interpretation).

 

 

ayyz
Level: Powered On

Re: Custom API to file upload

Thank you very much for the speedy reply

 

Ideally i want the REST service to accept multipart data. We tried various configuration but unfortunately it always throws error while creating the CustomAPI connection in PowerApps. Could you please provide me a sample swagger definition for the same

 

Cheers

 

Ayyanar.M

Power Automate Staff SameerCh
Power Automate Staff

Re: Custom API to file upload

Unfortunately, multipart data doesnt work today.  It is a limitation that we plan to address in future.  When it works, we will use "formData" as defined in the open api/swagger spec.

 

ayyz
Level: Powered On

Re: Custom API to file upload

In that case do u think the following is good enough

 

/{community_id}/rooms/{room_id}/content/{id}/children:
    post:
      operationId: uploadFile
      summary: Upload single file to folder
      description: |
        The single file upload endpoint çreates file in folder.
        The response includes status and meta info about created file.
      security:
        - OauthSecurity: []
      consumes:
        - application/json # and/or application/x-www-form-urlencoded
      parameters:
        - $ref: "#/parameters/community_id"
        - $ref: "#/parameters/room_id"
        - $ref: "#/parameters/id"
        - name: file
          in: body
          description: Uploaded file data
          required: true
          schema:
            $ref: '#/definitions/File'
        
      tags:
        - Upload file
      responses:
        '200':
          description: File is succesfully uploaded
        '400':
          $ref: "#/responses/ValidationError"
        '401':
          $ref: "#/responses/AuthenticationError"
        '403':
          $ref: "#/responses/AuthorizationError"
        '404':
          $ref: "#/responses/NotFoundError"
        '500':
          $ref: "#/responses/UnexpectedError"

definitions:

  File:
    description: The file object
    type: object
    properties:
      name: 
        description: Name of file
        type: string
      file: 
        description: File content
        type: string
        format: byte
Fvamaro
Level: Powered On

Re: Custom API to file upload

Hi @ayyz,

(I'm having some issues with a project similar to yours, can you help me?)

 

I'm integrating a personal App(asp.Net) with Microsoft Flow.
One of the main goals is to have a Custom connector that can send/receive files from my app storage(Azure storage) to the Microsoft applications (OneDrive, outlook, etc) using Microsoft flow.
However I'm getting some issues manipulating Files.

Let me show you an example:

Flow.PNG

 

In this Flow when an email is flagged I must save the attachment in my app storage.

 

 

 

 

 

 

 

 

 

 

 

 

 

Doc_Content : The attachment content;
Cont_ID : The azure container where the file will be save;
Doc_Name : Attachment Name;

 

 

 

 

 

 

 

 

And I receive the parameters like this:Containers OP.PNG

 

 

 

 

 

 

 

 

Doc_Content is a string because I think that 'Content' its a string base64 (am I rigth?)

I need to know how can I receive and send files between my App and Flow( connectors):
    ->Whats the type of 'Content'? How can I use it to get a byte[]?

 

 

Best reagrds,

Filipe Amaro

Helpful resources

Announcements
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!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,442)