Skip to content

MultiPartBody: Impossible to add multiple Body Parts with the same name #529

@romanett

Description

@romanett

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

I am using an existing API with the Atteached API Spec.

It expects a multipart body with an array of files:

e.g swagger Editor lets you paste multiple files:

Image

However the KIOTA Multipart body uses a dictionary based on the Part name, so this does not allow you to create such a body:

            body.AddOrReplacePart<byte[]>("files", "text/plain", file, "test.txt");
            body.AddOrReplacePart<byte[]>("files", "text/plain", file, "test2.txt");

 if(!_parts.TryAdd(partName, value))
 {
     _parts[partName] = value;
 }

This creates such a request:

RequestRaw:

--d11b4f38539b40fbb6a300dfddcede33
Content-Type: text/plain
Content-Disposition: form-data; name="files"; filename="test.txt"

Test

--d11b4f38539b40fbb6a300dfddcede33--

However I want to create such an request:

--d11b4f38539b40fbb6a300dfddcede33
Content-Type: text/plain
Content-Disposition: form-data; name="files"; filename="test.txt"

Test

--d11b4f38539b40fbb6a300dfddcede33
Content-Type: text/plain
Content-Disposition: form-data; name="files"; filename="test2.txt"

Test2

--d11b4f38539b40fbb6a300dfddcede33--

Expected behavior

Be able to create a multipart body with multiple elements with the same name.

How to reproduce

Generate client with attached API spec.

Try to add multiple files

Open API description file


openapi: 3.0.1
info:
  title: Test
  version: 1.0.0.0
paths:
  /v6/mailbox/messages:
    put:
      summary: Insert a message into a Mailbox
      description: |
        ## This endpoint inserts a message into the specified mailbox.
        **Returns** an object with ids for the newly created message
      operationId: putMessageV6
      requestBody:

        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/CreateMessage'
            encoding:
              files:
                contentType: application/octet-stream
      responses:
        '200':
          description: |
            The id of the created message is returned.
components:
  schemas:
    CreateMessage:
      type: object
      properties:
        files:
          type: array
          items:
            type: string
            description: |-
              files to upload.

              ### curl example:

              ```-F 'files=@sample.txt;type=text/plain'```
            format: binary
      description: |
        ### curl example:
        ```-F 'files=@sample.txt;type=text/plain;'```

Kiota Version

1.23.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

Configuration

OS: Windows 10
Architecture x64
.Net 9

Debug output

Click to expand log ```
</details>


### Other information

Repro project will follow

Metadata

Metadata

Assignees

No one assigned

    Labels

    WIPhelp wantedStandard GitHub labelpriority:p2Medium. For a p2 bug, generally have a work-around. Bug SLA <=30 daystype: bugA broken experience

    Type

    No fields configured for Bug.

    Projects

    Status
    Done ✔️

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions