Logic Apps Custom Connector: file content in body

Alexander Heinze 0 Reputation points
2023-01-15T10:21:49.2566667+00:00

Based on an OpenAPI v2 definition I have created a custom connector. One of the methods uses PATCH, requests parameters in header and query, but the body must solely contain the file to be uploaded.

The swagger definition looks like this:

    patch:
      tags: [EdmFileSet]
      summary: Update entity in EdmFileSet
      description: Update entity in EdmFileSet
      operationId: UpdateEdmFileSet
      produces: [application/json]
      parameters:
      - in: body
        name: EdmFile-UpdateBodyParam
        description: Updated EdmFile object
        required: true
        schema: {$ref: '#/definitions/EdmFile-Update'}

And the raw output shows

    "body": {
        "FileData":"......." 

This however doesn't work as the API expects the raw file data in the body, not a JSON element.

How do I need to modify the swagger definition so that only the file content itself is sent as a body without any extra attributes?

Thanks for your help.

Alex

Community Center Not monitored
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Dimple Rane 921 Reputation points MVP
    2023-01-15T10:25:36+00:00

    You can modify the swagger definition by changing the "in" value from "body" to "formData" and updating the "schema" property to use the "type" of "file" instead of "$ref".

    This should look like:

     patch:
          tags: [EdmFileSet]
          summary: Update entity in EdmFileSet
          description: Update entity in EdmFileSet
          operationId: UpdateEdmFileSet
          produces: [application/json]
          parameters:
          - in: formData
            name: FileData
            description: The file to be uploaded
            required: true
            type: file
    

    This way, the parameter will be sent as "form data" instead of in the request body, and the client will know it should send the file contents as raw data rather than a JSON object.

    1 person found this answer helpful.
    0 comments No comments

  2. Alexander Heinze 0 Reputation points
    2023-01-16T22:41:22.0233333+00:00

    Thanks Dimple. I have changed the type to "file" and was then forced by the Swagger editor to also add consumes: [multipart/form-data]

    The result however is still a JSON:

        "body": {
            "$content-type": "multipart/form-data",
            "$multipart": [
                {
                    "body": {
                        "$content-type": "image/jpeg",
                        "$content": "..."
                    }
    
                    "headers": {
                        "Content-Disposition": "form-data; name=\"FileData\""
                    }
                }
            ]
        }
    
    0 comments No comments

  3. Alexander Heinze 0 Reputation points
    2023-01-23T17:04:16.34+00:00

    Essentially, what I'm trying to achieve is to have a connector similar to the standard HTTP connector that simply accepts an argument as the body payload. I have successfully called my API using the HTTP connector for testing purposes, so would be curious how to build a custom connector that behaves in the same way.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.